{"id":18256899,"url":"https://github.com/mediacomem/superrest","last_synced_at":"2025-04-08T22:29:00.195Z","repository":{"id":73832573,"uuid":"112498101","full_name":"MediaComem/superrest","owner":"MediaComem","description":"SuperTest helpers to test REST APIs.","archived":false,"fork":false,"pushed_at":"2017-11-29T16:22:42.000Z","size":67,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-15T00:26:08.083Z","etag":null,"topics":["api","rest","supertest"],"latest_commit_sha":null,"homepage":"https://mediacomem.github.io/superrest/SuperRest.html","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/MediaComem.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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":"2017-11-29T16:16:06.000Z","updated_at":"2017-11-29T16:26:11.000Z","dependencies_parsed_at":null,"dependency_job_id":"76ef1b0e-5ebd-4c58-8d67-85bc76776640","html_url":"https://github.com/MediaComem/superrest","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MediaComem%2Fsuperrest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MediaComem%2Fsuperrest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MediaComem%2Fsuperrest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MediaComem%2Fsuperrest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MediaComem","download_url":"https://codeload.github.com/MediaComem/superrest/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247938575,"owners_count":21021553,"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","rest","supertest"],"created_at":"2024-11-05T10:24:03.580Z","updated_at":"2025-04-08T22:29:00.188Z","avatar_url":"https://github.com/MediaComem.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SuperREST\n\n[SuperTest](https://github.com/visionmedia/supertest) helpers to test REST APIs.\n\n[![npm version](https://badge.fury.io/js/superrest.svg)](https://badge.fury.io/js/superrest)\n[![Dependency Status](https://gemnasium.com/badges/github.com/MediaComem/superrest.svg)](https://gemnasium.com/github.com/MediaComem/superrest)\n[![Build Status](https://travis-ci.org/MediaComem/superrest.svg?branch=master)](https://travis-ci.org/MediaComem/superrest)\n[![Coverage Status](https://coveralls.io/repos/github/MediaComem/superrest/badge.svg?branch=master)](https://coveralls.io/github/MediaComem/superrest?branch=master)\n[![License](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE.txt)\n\n\u003c!-- START doctoc generated TOC please keep comment here to allow auto update --\u003e\n\u003c!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --\u003e\n\n\n- [Installation](#installation)\n- [Usage](#usage)\n- [Documentation](#documentation)\n  - [Basics](#basics)\n  - [Extending SuperREST](#extending-superrest)\n\n\u003c!-- END doctoc generated TOC please keep comment here to allow auto update --\u003e\n\nRead the [source code documentation](https://mediacomem.github.io/superrest/SuperRest.html).\n\nDeveloped at the [Media Engineering Institute](http://mei.heig-vd.ch) ([HEIG-VD](https://heig-vd.ch)).\n\n\n\n## Installation\n\n```bash\n$\u003e npm install --save-dev superrest\n```\n\n\n\n## Usage\n\n**SuperREST** is simply a wrapper around [SuperTest](https://github.com/visionmedia/supertest) that makes your work easier when testing standard REST APIs and CRUD methods.\n\n```js\nconst SuperRest = require('superrest');\nconst app = require('./my-app');\n\n// Create a reusable SuperREST instance with configuration that applies\n// to your entire API. You only have to do this once.\nconst api = new SuperRest(app, {\n  expectedContentType: /^application\\/json/,\n  pathPrefix: '/api'\n});\n\ndescribe('My API', function() {\n  it('should create a user', async function() {\n    // The following automatically makes a POST request to \"/api/users\"\n    // (since \"/api\" is the \"pathPrefix\" option configured above), and\n    // asserts that:\n    //\n    // * The status code of the response is 201 Created\n    // * The Content-Type header of the response starts with application/json\n    //   (as configured in the \"expectedContentType\" prefix above)\n    const res = await api.create('/users', { name: 'John Doe' });\n    expect(res.body).to.eql({ id: 1, name: 'John Doe' });\n  });\n});\n```\n\n\n\n## Documentation\n\nRead the [source code documentation](https://mediacomem.github.io/superrest/SuperRest.html) to know how to initialize and use a SuperREST instance.\n\n### Basics\n\nAll SuperREST does is pre-initialize a SuperTest chain with sane defaults for\nREST APIs and return it.  Its `test` method does that; it also has `create`,\n`update`, `retrieve`, `delete` and other CRUD methods which are simply aliases\nfor convenience.\n\nThe following code illustrates what SuperREST does:\n\n```js\n// SuperREST\nconst api = new SuperRest(app, {\n  expectedContentType: /^application\\/json/,\n  pathPrefix: '/api'\n});\n\n// Using the `test` method\nconst testChain = api.test('POST', '/users', { foo: 'bar' });\n\n// Using the `post` alias method\nconst postTestChain = api.post('/users', { foo: 'bar' });\n\n// Equivalent SuperTest chain\nconst superTestChain = supertest(app)\n  .post('/api/users')\n  .send({ foo: 'bar' })\n  .expect(res =\u003e {\n    // Assertions with chai (as an example)\n    expect(res.status).to.equal(201);\n    expect(res.contentType).to.match(/^application\\/json/);\n  });\n```\n\n### Extending SuperREST\n\nYou may extend the class exported by the module to add functionality, namely:\n\n* Override the `test` method to extend the returned SuperTest chain.\n* Override the `expect` method to add standard expectations.\n\nFor example:\n\n```js\nconst { expect } = require('chai');\nconst SuperRest = require('superrest');\n\nclass MySuperRest extends SuperRest {\n  test(method, path, body, options) {\n    // Add an Accept header to every request.\n    return super.test(method, path, body, options).set('Accept', 'application/json');\n  }\n\n  expect(res, options) {\n    super.expect(res, options);\n\n    // Check a custom X-Request-Duration header sent by the server.\n    expect(res.get('X-Request-Duration')).to.be.lte(100);\n  }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmediacomem%2Fsuperrest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmediacomem%2Fsuperrest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmediacomem%2Fsuperrest/lists"}