{"id":20081522,"url":"https://github.com/mihaibalint/crest-js","last_synced_at":"2026-06-08T12:31:26.869Z","repository":{"id":136683991,"uuid":"164793345","full_name":"MihaiBalint/crest-js","owner":"MihaiBalint","description":"Client for REST APIs (javascript)","archived":false,"fork":false,"pushed_at":"2019-10-03T18:26:04.000Z","size":345,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-13T01:42:56.639Z","etag":null,"topics":["api","http","rest","rest-api","rest-client","sdk"],"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/MihaiBalint.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-01-09T05:20:34.000Z","updated_at":"2019-10-03T18:19:58.000Z","dependencies_parsed_at":"2023-07-07T11:16:25.495Z","dependency_job_id":null,"html_url":"https://github.com/MihaiBalint/crest-js","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MihaiBalint%2Fcrest-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MihaiBalint%2Fcrest-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MihaiBalint%2Fcrest-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MihaiBalint%2Fcrest-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MihaiBalint","download_url":"https://codeload.github.com/MihaiBalint/crest-js/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241515927,"owners_count":19975139,"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":["api","http","rest","rest-api","rest-client","sdk"],"created_at":"2024-11-13T15:39:20.747Z","updated_at":"2026-06-08T12:31:26.836Z","avatar_url":"https://github.com/MihaiBalint.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# crest-js\n\nCrest JS is a small and friendly Client for REST APIs. Unlike most HTTP clients\nout there, Crest does not accept URLs as strings. URLs are instead constructed with\nJavascript Proxies and an opinionated convention for method names. This makes your\ncode more readable as you no longer have to understand the complex string shuffling\ncommonly associated with building URLs.\n\nInspired by [this medium article](https://medium.com/dailyjs/how-to-use-javascript-proxies-for-fun-and-profit-365579d4a9f8)\n\nCheck out the awesome examples below\n\n```js\nconst { crest } = require('crest-js');\n\n// Let's play with a contrived API for a database of companies and their staff\nconst api = crest({ baseUrl: 'https://api.example.com' })\n  .authorizationBasic('your-secret-here');\n```\n\nLet's try a simple HTTP request\n```js\napi\n  .getCompaniesBranches('11335577')\n  // translates to: GET /companies/11335577/branches\n\n  .then((branches) =\u003e {\n    console.log(', '.join(branches.map((branch) =\u003e branch.location)));\n  });\n```\n\nNow let's update the location for a company branch\n```js\napi\n  .putCompaniesBranches('11335577', '2468', {json: {location: '186 1st Avenue, NY'} })\n  // translates to: PUT /companies/11335577/branches/2468\n  // payload:       { \"location\": \"186 1st Avenue, NY\" }\n```\n\nAnd finally let's send a reminder to all staff accounts from a company branch. \n```js\nconst the_message = 'Remember to announce your time off before EOB today.';\napi\n  .getCompaniesStaff('11335577', {branch_id: '2468'})\n  // translates to: GET /companies/11335577/staff?branch_id=2468\n  \n  .then((staff) =\u003e {\n    return Promise.all(staff.map((member) =\u003e {\n\n      return api.postCompaniesStaffMessages('11335577', member.id, {json: {message: the_message}});\n      // translates to: POST /companies/11335577/staff/{id}/messages\n      // payload:       { \"message\": \"Remember to announce...\" }\n\n    }))\n    .then(() =\u003e {\n      console.log('Message sent.');\n    });\n  });\n```\n\nAlternatively we could do something with the github API using async/await\n```js\nconst github = crest({ baseUrl: 'https://api.github.com' })\n  .authorizationBasic('your-secret-here');\n\nconst orgs = await github.getUsersOrgs('MihaiBalint');\n// translates to: GET /users/MihaiBalint/orgs\n\nconst repos = await github.getUsersRepos('MihaiBalint');\n// translates to: GET /users/MihaiBalint/repos\n\n// POST /authorizations\nconst auth = await github.postAuthorizations({ json: { 'scopes': ['public_repo'] } });\n// translates to: POST /authorizations\n// payload:       { \"scopes\": [\"public_repo\"] }\n\n```\n\nSo what actually happened there? Crest converts camel-case method names to URLs\nand interpolates method arguments to obtain the url path. Query parameters and\nrequest payloads are added using dict arguments.\n\n### Custom request headers\n\nWhen you need to send some proproetary headers with every request, you could do the following:\n```js\nconst github = crest({ baseUrl: 'https://proprietary-api.example.com' })\n  .setCustomHeaders({ 'X-Custom-Header': 'your-proprietary-value' });\n\nconst bits = await github.getBits('proprietary');\n// translates to: GET /bits/proprietary with http headers:\n// X-Custom-Header: your-proprietary-value\n```\n\n## Installation\n\nnode:\n\n```\n$ npm install crest-js\n```\n\n## Running node tests\n\nInstall dependencies:\n\n```shell\n$ npm install\n$ npm test\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmihaibalint%2Fcrest-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmihaibalint%2Fcrest-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmihaibalint%2Fcrest-js/lists"}