Create mock responses to HTTP(S) requests for local development
This is a plugin for the serverless framework that provides the ability to create mock responses to HTTP(S) requests. This is useful when developing integration against an API spec that doesn't yet exist. This plugin uses nock to provide mock responses. It supports mock requests for:
An existing serverless framework project.
npm install serverless-offline-http-mock
yarn add serverless-offline-http-mock
serverless.yml file, enable the plugin by placing an
serverless-offline-http-mock entry in the plugins section.
If using Serverless Offline, make sure it is placed above the
serverless-offline-http-mock entry in the
For each host, create an entry containing hostname, a list of JS files to load, and an optional directory. See
serverless.yml example below.
In each JS file, export a function that accepts the nock library and hostname as arguments. Within that function, implement nock to handle the HTTP(S) requests. See
example.js example below.
... custom: serverless-offline-http-mock: - hostname: http://www.example.com directory: 'mocks' # Optional mocks: - example.js plugins: - serverless-offline-http-mock # Note how this comes before serverless-offline - serverless-offline
const mocks = (nock, hostname) => nock(hostname) .persist() .get('/') .reply(200, 'success!'); module.exports = mocks;
Latest commit b2f54ec on Sep 24, 2017