Skip to content
This repository has been archived by the owner on Oct 20, 2023. It is now read-only.

Commit

Permalink
Document sendFile option
Browse files Browse the repository at this point in the history
  • Loading branch information
mischah committed Dec 4, 2017
1 parent 3dff7e6 commit 7cfa013
Showing 1 changed file with 43 additions and 33 deletions.
76 changes: 43 additions & 33 deletions README.md
Expand Up @@ -11,6 +11,8 @@

> Build a fake backend by providing the content of JSON files or JavaScript objects through configurable routes.
*It actually can serve the content of other file types as well as sending the files itself as response.*

Comes as a Node.js server. Useful for mocking, testing and developing independent of the »real« backend.

## Example
Expand Down Expand Up @@ -93,6 +95,36 @@ module.exports = SetupEndpoint({
});
```

#### Advanced Example

`/server/api/anotherExample.js`:

```js
module.exports = SetupEndpoint({
name: 'anotherExample',
urls: [{
params: '/read',
requests: [{
method: 'GET',
response: '/response-files/anotherExample.json'
}]
}, {
params: '/update/{id}',
requests: [{
method: ['PUT', 'PATCH'],
response: {
success: true
}
}, {
method: 'DELETE',
response: {
deleted: true
}
}]
}, ]
});
```

#### Serving different content types

`/server/api/fileTypes.js`:
Expand All @@ -115,38 +147,13 @@ module.exports = SetupEndpoint({
params: '/html',
requests: [{
response: '/response-files/example.html',
statusCode: 201,
mimeType: 'text/html'
}]
}]
});
```

#### Advanced Example

`/server/api/anotherExample.js`:

```js
module.exports = SetupEndpoint({
name: 'anotherExample',
urls: [{
params: '/read',
requests: [{
method: 'GET',
response: '/response-files/anotherExample.json'
}]
}, {
params: '/update/{id}',
params: '/pdf',
requests: [{
method: ['PUT', 'PATCH'],
response: {
success: true
}
}, {
method: 'DELETE',
response: {
deleted: true
}
response: '/response-files/example.pdf',
sendFile: true
}]
}]
});
Expand Down Expand Up @@ -213,16 +220,19 @@ The configuration object in Detail:
* `string`, or `array` of strings.
* is used to define the http method(s) to which the endpoint will listen.
* `urls.requests.response`
* Could be a string pointing to a JSON template:
* Could be a string pointing to a file:
* `response: '/response-files/articles.json'`
* Or just a JavaScript object:
* `response: { success: true }`
* `urls.requests.mimeType`
* optional (string). Defaults to `application/json`.
* is used to set the `content-type` response header.
* Optional (string). Defaults to `application/json`.
* Is used to set the `content-type` response header.
* `urls.requests.sendFile`
* Optional (boolean). Defaults to `false`.
* Sends the file as response instead of returning the file content.
* `urls.requests.statusCode`
* Optional
* A status code (number)
* Optional (boolean). Defaults to `200`
* The HTTP status code of the response.
* Will return:
* a status code with a self defined response if you provide a response property
* a status code with a predefined error object provided by [boom](https://github.com/hapijs/boom) if you dont provide a response property for that request.
Expand Down

0 comments on commit 7cfa013

Please sign in to comment.