{"id":31754744,"url":"https://github.com/lukeed/ava-http","last_synced_at":"2025-10-09T18:23:24.801Z","repository":{"id":57151162,"uuid":"51119846","full_name":"lukeed/ava-http","owner":"lukeed","description":"Async HTTP request wrapper :rocket:","archived":false,"fork":false,"pushed_at":"2020-06-18T16:47:59.000Z","size":36,"stargazers_count":24,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-09-07T04:49:36.930Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lukeed.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-02-05T02:01:43.000Z","updated_at":"2025-02-11T15:48:28.000Z","dependencies_parsed_at":"2022-08-24T07:10:39.987Z","dependency_job_id":null,"html_url":"https://github.com/lukeed/ava-http","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/lukeed/ava-http","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukeed%2Fava-http","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukeed%2Fava-http/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukeed%2Fava-http/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukeed%2Fava-http/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lukeed","download_url":"https://codeload.github.com/lukeed/ava-http/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukeed%2Fava-http/sbom","scorecard":{"id":604414,"data":{"date":"2025-08-11","repo":{"name":"github.com/lukeed/ava-http","commit":"ba473072eeb87cc7b3b951d3c24e5b8296fa8b99"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":2.6,"checks":[{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Code-Review","score":0,"reason":"Found 2/30 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"License","score":0,"reason":"license file not detected","details":["Warn: project does not have a license file"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 2 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-21T01:15:11.541Z","repository_id":57151162,"created_at":"2025-08-21T01:15:11.541Z","updated_at":"2025-08-21T01:15:11.541Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279000777,"owners_count":26082911,"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","status":"online","status_checked_at":"2025-10-09T02:00:07.460Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":"2025-10-09T18:23:06.296Z","updated_at":"2025-10-09T18:23:24.795Z","avatar_url":"https://github.com/lukeed.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AVA-http\n\u003e Async HTTP requests.\n\n[![Build Status](https://travis-ci.org/lukeed/ava-http.svg?branch=master)](https://travis-ci.org/lukeed/ava-http)\n[![NPM version](https://img.shields.io/npm/v/ava-http.svg)](https://npmjs.org/package/ava-http)\n[![NPM version](https://img.shields.io/npm/dm/ava-http.svg)](https://npmjs.org/package/ava-http)\n\nAVA-http is a wrapper around the [Request-Promise](https://github.com/request/request-promise) library, making\nit simpler to initiate HTTP requests.\n\nIt was made for succint API testing within [AVA](https://github.com/sindresorhus/ava), but it can be used anywhere.\n\n## Installation\n```\nnpm install --save-dev ava-http\n```\n\n## Usage\n\nThe generic HTTP methods are included: [`get`, `post`, `put`, `delete`].\n\nEach of these, used within the context of an AVA test, will return a `Promise` that can be `await`ed, `yield`ed, or `then`/`catch`'d.\n\nErroneous responses will always return the *full* `Response` object and should be caught with `.catch()`.\n\nSuccessful responses will return the `payload` (aka, `response.body`) by default.\nIf you would also like the full `Response` object, exchange your `method` for `methodResponse`:\n\n* `http.get` ==\u003e `http.getResponse`\n* `http.post` ==\u003e `http.postResponse`\n* `http.put` ==\u003e `http.putResponse`\n* `http.del` ==\u003e `http.delResponse`\n\n## API\n### get(url[, options])\n\n\u003e `url`: `string`\n\n\u003e `options`: `object`\n\n**Returns:** `Promise`\n\nOn resolve success, returns `payload`. On error, returns full `Response` object.\n\n### getResponse(url[, options])\n\n\u003e `url`: `string`\n\n\u003e `options`: `object`\n\n**Returns:** `Promise`\n\nAlways returns full `Response` object.\n\n### post(url[, options])\n\n\u003e `url`: `string`\n\n\u003e `options`: `object`\n\n**Returns:** `Promise`\n\nOn resolve success, returns `payload`. On error, returns full `Response` object.\n\n### postResponse(url[, options])\n\n\u003e `url`: `string`\n\n\u003e `options`: `object`\n\n**Returns:** `Promise`\n\nAlways returns full `Response` object.\n\n### put(url[, options])\n\n\u003e `url`: `string`\n\n\u003e `options`: `object`\n\n**Returns:** `Promise`\n\nOn resolve success, returns `payload`. On error, returns full `Response` object.\n\n### putResponse(url[, options])\n\n\u003e `url`: `string`\n\n\u003e `options`: `object`\n\n**Returns:** `Promise`\n\nAlways returns full `Response` object.\n\n### del(url[, options])\n\n\u003e `url`: `string`\n\n\u003e `options`: `object`\n\n**Returns:** `Promise`\n\nOn resolve success, returns `payload`. On error, returns full `Response` object.\n\n### delResponse(url[, options])\n\n\u003e `url`: `string`\n\n\u003e `options`: `object`\n\n**Returns:** `Promise`\n\nAlways returns full `Response` object.\n\n## Options\n### form\n\n\u003e Type: `object`\n\n\u003e Default: `{}`\n\nAn object of `key:value` pairs of formdata that will be urlencoded before reaching the server.\n\nThe request's `headers` will automatically include `'content-type': 'application/x-www-form-urlencoded'`.\n\nThis simulates sending an HTML form via normal means.\n\n### body\n\n\u003e Type: `object`\n\n\u003e Default: `{}`\n\nThe payload data to be sent to the server. Leave `json` as `true` to automatically stringify as JSON.\n\n### headers\n\n\u003e Type: `object`\n\n\u003e Default: `{}`\n\nThe request headers to send.\n\n### params\n\n\u003e Type: `object`\n\n\u003e Default: `{}`\n\nAn alias of `qs`.\n\n### qs\n\n\u003e Type: `object`\n\n\u003e Default: `{}`\n\nThe query string to append to the URL. See [this example](#passing-query-string-parameters).\n\n### json\n\n\u003e Type: `boolean`\n\n\u003e Default: `true`\n\nWhether or not the response body should be parsed as JSON.\n\n### transform\n\n\u003e Type: `function`\n\n\u003e Default: `null`\n\nTransform the response into a custom value with which the promise is resolved. See [here](https://github.com/request/request-promise#the-transform-function) for info.\n\n\n## AVA\n\n### Setup\nYou must have AVA installed already.\n\n```js\nimport test from 'ava';\nimport http from 'ava-http';\n\ntest('foo should succeed', async t =\u003e {\n\tconst res = await http.get('http://localhost/posts');\n\tt.true(typeof res === 'object'); // json object by default\n\tt.deepEqual(res, {expected: 'output'}); // deepEqual comparison\n});\n\ntest('bar should error', t =\u003e {\n\thttp.post('http://localhost/posts').catch(err =\u003e {\n\t\tt.is(err.statusCode, 400);\n\t\tt.deepEqual(err.response.body, {error: 'message'});\n\t});\n});\n```\n\n### Examples\n#### Thennables\n```js\ntest('thennable', async t =\u003e {\n\thttp.get('http://localhost').then(res =\u003e {\n\t\tt.deepEqual(res, {expected: 'output'});\n\t});\n});\n```\n\n#### Async Support\n```js\ntest('async/await', async t =\u003e {\n\tt.deepEqual(await http.get('http://localhost'), {expected: 'output'});\n});\n```\n\n#### Generator Support\n```js\ntest('generator/yield', function * (t) {\n\tt.deepEqual(yield http.get('http://localhost'), {expected: 'output'});\n});\n```\n\n#### Response Headers\nBy default, successful responses will only yield their payloads. If you need/want to test a status code, for example, this will suffice:\n\n```js\ntest('response headers', async t =\u003e {\n\tconst res = await http.getResponse('http://localhost');\n\tconsole.log('these are the headers: ', res.headers);\n\tt.is(res.statusCode, 200);\n});\n```\n\n#### Expecting Errors\n\nIn order to successfully expect and catch a Response Error, the test must be asserted witin the Promise's `.catch()`.\n\nFor more information, please check out Request-Promise's [excellent documentation on the Promise API](https://github.com/request/request-promise#api-in-detail).\n\n```js\ntest('404 error is thrown', async t =\u003e {\n\thttp.get('http://localhost').catch(err =\u003e t.is(err.statusCode, 404));\n});\n```\n\n#### Posting JSON\n```js\ntest('post json object', async t =\u003e {\n\tconst body = {some: 'data'};\n\tt.deepEqual(await http.post('http://localhost', {body}), {expected: 'output'});\n});\n\n// or, to also assert a statusCode...\ntest('post json object, assert status', async t =\u003e {\n\tconst body = {some: 'data'};\n\tconst res = await http.postResponse('http://localhost', {body});\n\tt.is(res.statusCode, 201);\n\tt.deepEqual(res.response.body, {expected: 'output'});\n});\n```\n\n#### Posting as a HTML Form\nAll data within the `form` object will be `urlencoded`, just as any normal `\u003cform\u003e` would!\n\n```js\ntest('post like a form', async t =\u003e {\n\tconst form = {some: 'data'}; // will be urlencoded\n\tt.deepEqual(await http.post('http://localhost', {form}), {expected: 'output'});\n});\n```\n\n#### Updating an Item\n```js\ntest('update an item', async t =\u003e {\n\tconst body = {some: 'data'};\n\tt.deepEqual(await http.put('http://localhost/items/2', {body}), {expected: 'output'});\n});\n```\n\n#### Deleting an Item\n```js\ntest('delete an item', async t =\u003e {\n\tconst res = await http.delResponse('http://localhost/items/2');\n\tt.is(res.statusCode, 200);\n});\n\n// expecting an error...\ntest('delete is unauthorized', async t =\u003e {\n\thttp.del('http://localhost/items/2').catch(err =\u003e t.is(err.statusCode, 401));\n});\n```\n\n#### Pass an Authorization Token (eg, JWT)\n```js\ntest('delete is authorized with token', async t =\u003e {\n\tconst headers = {\n        'Authorization': 'Bearer 1234567890'\n\t};\n\tt.deepEqual(await http.del('http://localhost/items/2', {headers}), {expected: 'output'});\n});\n```\n\n#### Passing Query String Parameters\n```js\ntest('get item with parameters', async t =\u003e {\n\tconst params = {\n\t\ttoken: 'xxxxx xxxxx' // -\u003e uri + '?token=xxxxx%20xxxxx'\n\t};\n\tt.deepEqual(await http.get('http://localhost', {params}), {expected: 'output'});\n});\n```\n\n## Goals\nIdeally, AVA-http is the asynchronous, node-equivalent of PHPUnit. This means that similar, custom assertions will be added into AVA's Test class (as opposed to exporting an `http` wrapper, as it currently stands). Methods will/should be as follows:\n\n* `t.jsonEquals`\n* `t.jsonContains`\n* `t.jsonStructure`\n* `t.responseOk`\n* `t.responseNotOk`\n* `t.responseCode`\n* `t.responseType`\n* `t.headersEqual`\n* `t.headersContain`\n\nAn ideal test setup may look like this:\n\n```js\ntest(async t =\u003e {\n\tt.responseOk(await get(url)); // no error\n});\n\ntest(async t =\u003e {\n\tconst body = {sent: 'data'};\n\tt.jsonContains(await post(url, {body}), {message: 'success'});\n});\n\ntest(async t =\u003e {\n\tt.jsonEquals(await get(url), {exact: 'match'});\n});\n\ntest(async =\u003e {\n\tt.responseCode(await get(url), 301);\n});\n\ntest(async =\u003e {\n\tt.headersContain(await get(url), {'Cache-Control': 'max-age=21600'});\n});\n```\n\n## TODOs\n- [ ] Define a complete Micro test server, with routing\n- [ ] Start-up test server on `test.before()`\n- [ ] Cleanup/Remove all `const url = await ...` within tests\n\n## License\nMIT © [Luke Edwards](https://lukeed.com) et [al](https://github.com/lukeed/ava-http/graphs/contributors)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flukeed%2Fava-http","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flukeed%2Fava-http","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flukeed%2Fava-http/lists"}