Skip to content

Commit

Permalink
feat(scully): allow specify headers when using the JSON plugin (#140)
Browse files Browse the repository at this point in the history
user can specify a `headers` object in ths `scully.config.js`.
This headers will be passed throught the request when calling the
specified endpoint.

Closes #137
  • Loading branch information
d-koppenhagen authored and aaronfrost committed Jan 4, 2020
1 parent bda9686 commit 8415355
Show file tree
Hide file tree
Showing 7 changed files with 224 additions and 133 deletions.
22 changes: 21 additions & 1 deletion docs/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ exports.config = {
```

The following is an example that uses the [jsonplaceholder](https://jsonplaceholder.typicode.com/) to fetch a list of
User IDs for my app. It uses the `json` plugin.
User IDs for my app. It uses the [JSON Plugin](../scully/routerPlugins/jsonRoutePlugin.ts) which is already part of Scully.

```javascript
// scully.config.js
Expand All @@ -113,6 +113,26 @@ second is `property`. The JSON plugin will pluck the provided property name fro
means that the array returned by the jsonplaceholder api will each have an `id` property. So instead of returning a list
users, it will return a list of userIds.

The JSON Plugin will optionally accept also a header configuration where you can set specific header that you may have to sent when requesting an API:

```javascript
// scully.config.js
exports.config = {
routes: {
"/todos/:todoId": {
"type": "json",
"todoId": {
"url": "https://my-api.com/todos",
"property": "id",
"headers": {
"API-KEY": "0123456789"
}
}
}
}
};
```

### <a name="router-plugin-configure"></a> Router Plugin Examples
For those looking to build router plugins for their app, here are links to the built-in __router plugins__ in Scully:
- [JSON Plugin](../scully/routerPlugins/jsonRoutePlugin.ts)
Expand Down
Loading

0 comments on commit 8415355

Please sign in to comment.