{"_id":"5523e1117a36b22b0088654b","version":{"_id":"550ada9d921b7d0d00228876","forked_from":"550a3b2542fff40d00ae5ffb","project":"550a379f635c660d00527fd8","__v":3,"createdAt":"2015-03-19T14:18:05.245Z","releaseDate":"2015-03-19T14:18:05.245Z","categories":["550ada9d921b7d0d00228877","550ada9d921b7d0d00228878","550ada9d921b7d0d00228879","550ada9d921b7d0d0022887a","550ada9d921b7d0d0022887b","550ada9d921b7d0d0022887c","550ada9d921b7d0d0022887d","5523e61e71c0542100993493","55246f72ccc28a0d0062c560"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"3.0.0","version":"3.0.0"},"__v":24,"user":"550a378e635c660d00527fd7","category":{"_id":"55246f72ccc28a0d0062c560","version":"550ada9d921b7d0d00228876","__v":1,"pages":["55356d8ee3f0920d004f5c54"],"project":"550a379f635c660d00527fd8","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-04-07T23:59:46.143Z","from_sync":false,"order":3,"slug":"general-usage","title":"General Usage"},"project":"550a379f635c660d00527fd8","updates":[],"next":{"pages":[],"description":""},"createdAt":"2015-04-07T13:52:17.578Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"auth":"required","params":[],"url":""},"isReference":false,"order":0,"body":"Calls in Snoocore map *directly* to the Reddit API. \n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Overview\"\n}\n[/block]\nHere is an example of an endpoint that appears in the reddit API documentation. ([link](https://www.reddit.com/dev/api#GET_hot))\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/LO3y0dRGRuCogtwgMpcB_I4ILRpY.png\",\n        \"I4ILRpY.png\",\n        \"1244\",\n        \"462\",\n        \"#f38c45\",\n        \"\"\n      ]\n    }\n  ]\n}\n[/block]\n## Endpoint URL parameters\n\nIn the reddit documentation, URL parameters are *italicized*. You can replace the italics with a valid value.\n\nSometimes, URL parameters & sections of the path are optional and are surrounded in [brackets]. The section in brackets can be omitted completely.\n\nThe above endpoint can be structured as:\n\n- `/r/subreddit/hot` (filling in a value for the subreddit)\n- `/hot` (omitting the brackets)\n\n## Endpoint arguments\n\nMost endpoints take arguments that customize the call. They are listed in a table below the endpoint.\n\nIn the above endpoint, those would be `after`, `before`, `count`, `limit`, and `show`.\n\n## Endpoint method\n\nIn the above endpoint, the method is `GET`.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Basic Call (no URL parameters, no arguments)\"\n}\n[/block]\nTo use the endpoint ([`GET [/r/subreddit]/hot` (link)](https://www.reddit.com/dev/api#GET_hot)) without url parameters and without arguments use the following code:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"var promise = reddit('/hot').get();\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\nIt is possible to determine what to call based on the path (in this case `/hot`) and the HTTP verb that is uses (in this case `GET`). \n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Call an endpoint with arguments (no URL parameters)\"\n}\n[/block]\nThe `/hot` endpoint can take arguments such as `limit`. To specify arguments, pass them  in as an object:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"var promise = reddit('/hot').get({\\n\\tlimit: 100\\n});\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n## A note on `uh / X-Modhash header` arguments\n\nSnoocore enforces OAuth, therefore this argument is not needed in any request and can be safely ignored.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Call with URL parameters\"\n}\n[/block]\nWe can embed the url parameter into the path directly:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"// Get 50 posts from /r/netsec\\nvar promise = reddit('/r/netsec/hot').get({\\n  limit: 50\\n});\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\nIt is also possible to use a placeholder value starting with `'$'` to include the parameter inside of the arguments:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"// Get 50 posts from /r/netsec\\nvar promise = reddit('/r/$subreddit/hot').get({\\n  limit: 50,\\n  $subreddit: 'netsec'\\n});\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Final Example\"\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"var Snoocore = require('snoocore');\\n\\nvar reddit = new Snoocore({\\n  userAgent: 'test:::at:::documentation',\\n  oauth: {\\n    type: 'implicit',\\n    key: 'cSv7AOyu6CV3gA',\\n    redirectUri: 'https://snoocore.readme.io',\\n    scope: [ 'read' ]\\n  }\\n});\\n\\nreddit('/r/netsec/hot').get().then(console.log);\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"success\",\n  \"title\": \"Finished!\",\n  \"body\": \"Check out how to change how a single call behaves with [Call Context Options](doc:call-context-options) .\"\n}\n[/block]","excerpt":"","slug":"making-a-call","type":"basic","title":"Making a call"}
Calls in Snoocore map *directly* to the Reddit API. [block:api-header] { "type": "basic", "title": "Overview" } [/block] Here is an example of an endpoint that appears in the reddit API documentation. ([link](https://www.reddit.com/dev/api#GET_hot)) [block:image] { "images": [ { "image": [ "https://files.readme.io/LO3y0dRGRuCogtwgMpcB_I4ILRpY.png", "I4ILRpY.png", "1244", "462", "#f38c45", "" ] } ] } [/block] ## Endpoint URL parameters In the reddit documentation, URL parameters are *italicized*. You can replace the italics with a valid value. Sometimes, URL parameters & sections of the path are optional and are surrounded in [brackets]. The section in brackets can be omitted completely. The above endpoint can be structured as: - `/r/subreddit/hot` (filling in a value for the subreddit) - `/hot` (omitting the brackets) ## Endpoint arguments Most endpoints take arguments that customize the call. They are listed in a table below the endpoint. In the above endpoint, those would be `after`, `before`, `count`, `limit`, and `show`. ## Endpoint method In the above endpoint, the method is `GET`. [block:api-header] { "type": "basic", "title": "Basic Call (no URL parameters, no arguments)" } [/block] To use the endpoint ([`GET [/r/subreddit]/hot` (link)](https://www.reddit.com/dev/api#GET_hot)) without url parameters and without arguments use the following code: [block:code] { "codes": [ { "code": "var promise = reddit('/hot').get();", "language": "javascript" } ] } [/block] It is possible to determine what to call based on the path (in this case `/hot`) and the HTTP verb that is uses (in this case `GET`). [block:api-header] { "type": "basic", "title": "Call an endpoint with arguments (no URL parameters)" } [/block] The `/hot` endpoint can take arguments such as `limit`. To specify arguments, pass them in as an object: [block:code] { "codes": [ { "code": "var promise = reddit('/hot').get({\n\tlimit: 100\n});", "language": "javascript" } ] } [/block] ## A note on `uh / X-Modhash header` arguments Snoocore enforces OAuth, therefore this argument is not needed in any request and can be safely ignored. [block:api-header] { "type": "basic", "title": "Call with URL parameters" } [/block] We can embed the url parameter into the path directly: [block:code] { "codes": [ { "code": "// Get 50 posts from /r/netsec\nvar promise = reddit('/r/netsec/hot').get({\n limit: 50\n});", "language": "javascript" } ] } [/block] It is also possible to use a placeholder value starting with `'$'` to include the parameter inside of the arguments: [block:code] { "codes": [ { "code": "// Get 50 posts from /r/netsec\nvar promise = reddit('/r/$subreddit/hot').get({\n limit: 50,\n $subreddit: 'netsec'\n});", "language": "javascript" } ] } [/block] [block:api-header] { "type": "basic", "title": "Final Example" } [/block] [block:code] { "codes": [ { "code": "var Snoocore = require('snoocore');\n\nvar reddit = new Snoocore({\n userAgent: 'test@documentation',\n oauth: {\n type: 'implicit',\n key: 'cSv7AOyu6CV3gA',\n redirectUri: 'https://snoocore.readme.io',\n scope: [ 'read' ]\n }\n});\n\nreddit('/r/netsec/hot').get().then(console.log);", "language": "javascript" } ] } [/block] [block:callout] { "type": "success", "title": "Finished!", "body": "Check out how to change how a single call behaves with [Call Context Options](doc:call-context-options) ." } [/block]