HTTP Request Methods

All of the Frisby.js HTTP methods are based on the fetch() API standard. Frisby.js offers pre-defined get, post, put, and del for convenience and better readability.

If you need to do something custom like send requests through a proxy, you can also use fetch method directly with custom options from the fetch spec.

frisby.get(url)

Issues an HTTP GET request.

Don't forget to call done at the end of your it since Frisby is making an async HTTP call.

const frisby = require('frisby');

it ('GET should return a status of 200 OK', function (done) {
  frisby
    .get('http://api.example.com/posts')
    .expect('status', 200)
    .done(done);
});

frisby.post(url, [params])

Issues an HTTP POST request, with optional provided parameters.

Assumes JSON and sends the header Content-Type: application/json by default.

const frisby = require('frisby');

it ('POST should return a status of 201 Created', function (done) {
  frisby
    .post('http://api.example.com/posts', {
      title: 'My New Blog Post',
      content: '<p>A cool blog post!</p>'
    })
    .expect('status', 201)
    .done(done);
});

frisby.put(url, [params])

Issues an HTTP PUT request, with optional provided parameters. Semantics are the same as frisby.post().

const frisby = require('frisby');

it ('POST should return a status of 200 OK', function (done) {
  frisby
    .put('http://api.example.com/posts/1', {
      title: 'My Updated Title',
      content: '<p>Some different content actually</p>'
    })
    .expect('status', 200)
    .done(done);
});

frisby.del(url)

Issues an HTTP DELETE request.

const frisby = require('frisby');

it ('DELETE should return a status of 204 No Content', function (done) {
  frisby
    .del('http://api.example.com/posts/1')
    .expect('status', 204)
    .done(done);
});

frisby.fetch(url, [options])

If you need to do something custom, or if for some reason none of the above helper HTTP methods suit your needs, you can use fetch directly, which accepts all the same options and parameters as the Fetch API - Frisby.js just passes them through for your request.

const frisby = require('frisby');

it ('fetch with POST should return a status of 201 Created', function (done) {
  frisby
    .fetch('http://api.example.com/posts', {
      method: 'POST',
      body: JSON.stringify({
        title: 'My Updated Title',
        content: '<p>Some different content actually</p>'
      })
    })
    .expect('status', 201)
    .done(done);
});

results matching ""

    No results matching ""