Skip to content

Commit 8415355

Browse files
d-koppenhagenaaronfrost
authored andcommitted
feat(scully): allow specify headers when using the JSON plugin (#140)
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
1 parent bda9686 commit 8415355

File tree

7 files changed

+224
-133
lines changed

7 files changed

+224
-133
lines changed

docs/plugins.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ exports.config = {
8888
```
8989

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

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

116+
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:
117+
118+
```javascript
119+
// scully.config.js
120+
exports.config = {
121+
routes: {
122+
"/todos/:todoId": {
123+
"type": "json",
124+
"todoId": {
125+
"url": "https://my-api.com/todos",
126+
"property": "id",
127+
"headers": {
128+
"API-KEY": "0123456789"
129+
}
130+
}
131+
}
132+
}
133+
};
134+
```
135+
116136
### <a name="router-plugin-configure"></a> Router Plugin Examples
117137
For those looking to build router plugins for their app, here are links to the built-in __router plugins__ in Scully:
118138
- [JSON Plugin](../scully/routerPlugins/jsonRoutePlugin.ts)

0 commit comments

Comments
 (0)