Displaying posts of a subreddit
Before proceeding further, let's discuss the reddit API. Reddit provides a REST-based API and multiple response formats for the data. Out of these, the simplest is adding .json
to a URL and accessing it. Adding .json
at the end of any URL will get us the JSON object for that page. You can try it yourself. If you want to get the JSON for webdev
subreddit, enter the URL http://reddit.com/r/webdev.json in your browser and you will see the JSON response. If you want to see the formatted JSON, use Google Chrome. Similarly, to get the comments JSON for any particular post, the URL becomes http://reddit.com/comments/XYZ.json
, where XYZ is the id
for that post. You will learn how to find the id
as well in this section.
There is a restriction in browsers that you need to be aware of. Browsers do not allow you to make cross-domain AJAX requests. It means if your application is running on the domain abc.com
, you cannot make AJAX requests to any other domain except that...