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.

const frisby = require('frisby');

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

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 () {
  return frisby
    .post('http://api.example.com/posts', {
      title: 'My New Blog Post',
      content: '<p>A cool blog post!</p>'
    })
    .expect('status', 201);
});

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 () {
  return frisby
    .put('http://api.example.com/posts/1', {
      title: 'My Updated Title',
      content: '<p>Some different content actually</p>'
    })
    .expect('status', 200);
});

frisby.del(url)

Issues an HTTP DELETE request.

const frisby = require('frisby');

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

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 () {
  return 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);
});

Last updated