{"id":17014462,"url":"https://github.com/maradotwebp/apidown","last_synced_at":"2025-04-12T09:19:31.725Z","repository":{"id":57182116,"uuid":"105399767","full_name":"maradotwebp/apidown","owner":"maradotwebp","description":":arrow_double_down: A middleman for APIs. Download, cache, get 100% uptime.","archived":false,"fork":false,"pushed_at":"2019-06-08T12:50:34.000Z","size":71,"stargazers_count":3,"open_issues_count":2,"forks_count":14,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-31T21:35:20.383Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/maradotwebp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-09-30T20:45:19.000Z","updated_at":"2019-06-08T13:24:42.000Z","dependencies_parsed_at":"2022-09-14T04:41:34.293Z","dependency_job_id":null,"html_url":"https://github.com/maradotwebp/apidown","commit_stats":null,"previous_names":["maradotwebp/apidown","froehlicha/apidown"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maradotwebp%2Fapidown","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maradotwebp%2Fapidown/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maradotwebp%2Fapidown/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maradotwebp%2Fapidown/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/maradotwebp","download_url":"https://codeload.github.com/maradotwebp/apidown/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248369296,"owners_count":21092550,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-14T06:25:01.372Z","updated_at":"2025-04-12T09:19:31.703Z","avatar_url":"https://github.com/maradotwebp.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# apidown [![Build Status](https://travis-ci.org/froehlichA/apidown.svg?branch=master)](https://travis-ci.org/froehlichA/apidown) [![Coverage Status](https://coveralls.io/repos/github/froehlichA/apidown/badge.svg?branch=master)](https://coveralls.io/github/froehlichA/apidown?branch=master)\n:arrow_double_down: A middleman for APIs. Download, cache, get 100% uptime.\n\n## History\nThis application is beginner-friendly, and made for [Hacktoberfest 2017](https://hacktoberfest.digitalocean.com/), and should serve as a starting point for javascript open-source developers.\n\nIf you would like to contribute, follow [Contributing.md](CONTRIBUTING.md).\n\n## Documentation\nYou can register an api with the following commands:\n```javascript\nconst api = require('apimust');\nconst testapi = api.url('www.sample-api.com') //Root url of the api\ntestapi\n    .withPassword('CLEAN_TEXT_PASSWORD') //Add password auth\n    .withHeaders({ 'User-Agent': 'mozilla' }) //Custom http headers\n```\nThen, you can use apimust to fetch data from the server, and automatically cache data in the process.\n```javascript\n//Fetches the body of www.sample-api.com/users, and saves the data in the cache.\ntestapi.fetch('/users', function(err, result) {\n    if(err) console.log(err);\n    if(result) console.log(result);\n})\n```\n\nYou can set `options.parseJson` to `true` in order to automatically parse return body as JSON object.  \n\nIn case your input endpoint doesnt capable to return JSON format, the underlying system will handle error case and normally return error.\n\n```javascript\n//Using fetch on the same endpoint will fetch from cache now, and load much faster on slow connections.\ntestapi.fetch('/users', function(err, result) {\n    if(err) console.log(err);\n    if(result) console.log(result);\n})\n```\n\nYou can also integrate options into the ```fetch``` method:\n```javascript\nconst options = {\n    preferOnline: true //Will try to fetch online first, and resort to cache as a fallback\n    headers: {\n        'User-Agent': 'mozilla' //Will add custom headers\n    }\n}\n\ntestapi.fetch('/users', function(err, result) {\n    if(err) console.log(err);\n    if(result) console.log(result);\n}, options)\n```\n\n## `defineEndpoint`\nYou can define an endpoint, which will return a function tied to a URL endpoint.\n### parameters\nThe parameters are:\n\n    1. url: the Url for the endpoint\n    2. method: the method for the endpoint (\"GET\", \"POST\", \"PUT\", \"DELETE\" or \"PATCH\")\n    3. headers: the headers for the endpoint (_optional_)\n    4. config: the config for this endpoint (_optional_)\n### Return\nThis returns a function that sends a request to the endpoint. This function takes the following parameters:\n\n    1. payload: this is the payload for the request (This is also used for formating the url)\n    2. headers: the headers for this request(_optional_)\n    3. config: The config for this request (_optional_)\n\n### Example\n```javascript\nlet endpoint = testApi.defineEndpoint(\"/users/:id\", \"GET\");\n\n//sends a request to /users/1234?example=yes\nendpoint({id: 1234, example: \"yes\"})\n.then(data =\u003e console.log(data))\n.catch(err =\u003e console.error(err))\n```\n\n## Predefined endpoint functions (`get`, `post`, `delete`, `update`)\nYou could also predefine api endpoints so that it is on the api object.\n### parameters\nThese are the parameters this takes\n\n    1. name: the name of the method\n    2. url: the Url for the endpoint\n    3. method: the method for the endpoint (\"GET\", \"POST\", \"PUT\", \"DELETE\" or \"PATCH\")\n    4. headers: the headers for the endpoint (_optional_)\n    5. config: the config for this endpoint (_optional_)\n\n### Return\nThis returns the API object with new methods that corresponds to the name you gave it.\nthis method takes all of the same parameters as `defineEndpoint`.\n\n### Example\n```javascript\ntestApi.get(\"all_users\", \"/users\");\n    .post(\"create_user\", \"/users\");\n    .get(\"single_user\", \"/users/:id\");\n    .update(\"update_user\", \"/users/:id\");\n    .delete(\"delete_user\", \"/users/:id\");\n```\n\nThis will attach these methods to `testApi`.\n```javascript\ntestApi.all_users(); //Sends a GET request to /users\ntestApi.create_user({...}); //Sends a POST request to /users\ntestApi.single_user({id: 1234}); //sends a GET request to /users/1234\n```\n\n## Resources\nInstead of defining each individual endpoint you can define a resource, which will attach appropiate methods to your endpoint.\n\n### Parameters\nThis takes the following parameters:\n\n    1. name: the name of the resource. this could also be the base url\n    2. methods: the methods this resource supports. (_optional_) defualts to [\"GET\", POST\", \"PUT\", \"DELETE\"]\n    3. headers: the headers for this resource\n    4. config: the config for this resource\n    5. base_url: the base_url for this resource, defaults to \"name\"\n    6. key: the key for the resource. Defaults to the \"id\".\n\n### Returns\nThis returns an object that has methods that sends out requests. These methods are `find`, `all`, `delete`, `create`, and `update` and are the same as described in the *Predefined endpoint functions* section.\n\n### Example \n```javascript\n//Creates a resource called users\ntestApi.resource(\"users\");\n```\n\nThis creates five methods on a `users` object on `testApi`: `find`, `all`, `delete`, `create`, and `update`. For example:\n```javascript\ntestApi.users.all(); //sends a GET request to /users\ntestApi.users.find({id: 1234}); //sends a GET request to /users/1234\ntestApi.users.create({...}); //sends a POST request to /users\ntestApi.users.delete({id: 1234}) //sends a DELETE request to /users/1234\ntestApi.users.update({id: 1234, ...}) //sends a PUT/PATCH request to /users/1234\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaradotwebp%2Fapidown","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaradotwebp%2Fapidown","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaradotwebp%2Fapidown/lists"}