-
Notifications
You must be signed in to change notification settings - Fork 6
Plugins
Yarkov Aleksey edited this page Feb 11, 2023
·
12 revisions
Allow to delay in sending response to client (in milliseconds)
{
"plugins": [
{
"name": "delay",
"args": { "duration": 500 }
}
]
}
Random is a plugin to generate random data
{
"plugins": [
{"name": "random"}
],
"request": { /* */ },
"response": {
"body": [
{
"id": "#random:int:min=1000&max=9999#",
"name": "#random:word:count=5#",
"age": "#random:int:min=10&max=100#",
"email": "#random:email#",
"is_enabled": "#random:bool#"
},
{
"id": "#random:int:min=1000&max=9999#",
"name": "#random:name:female=true#",
"age": "#random:int:min=10&max=100#",
"email": "#random:email#",
"uuid": "#random:uuid#"
}
]
}
}
This is a plugin to reflect current timestamp
{
"plugins": [
{
"name": "timestamp",
"args": { "in": "milliseconds" }
}
],
"request": { /* */ },
"response": {
"body": [
{
"id": 1
"name": "John Doe",
"created_at": "#timestamp#",
"updated_at": "#timestamp#"
}
]
}
}
This is a plugin to create a list of items. This plugin can be used with other plugins (e.g, random, timestamp) as long as it is placed above other plugins
{
"plugins": [
{
"name": "list",
"args": {
"count": 5,
"item": {
"name": "John",
"age": 35
}
}
}
],
"request": {
"method": "GET",
"path": "/list?body"
},
"response": {
"body": []
}
}
{
"plugins": [
{
"name": "list",
"args": {
"count": 5,
"item": {
"name": "John",
"age": 35
},
"field": "data"
}
}
],
"request": {
"method": "GET",
"path": "/list?field"
},
"response": {
"body": {
"data": [],
"pagination": {
"page": 1,
"count": 10,
"size": 5
}
}
}
}
This plugin allows to run external script and direct output to a field in response. For example, we can create a node.js script simply generates api signature and put the result in response's header
Arguments
-
cmd
: an array as command string -
dir
: working directory -
prop
: body's properties or header key -
section
: target section (header
orbody
) -
timeout
: define maximum execution time for command (in milliseconds) -
cache
: cache the result, it prevents faker from running command in certain time, so as to improve speed -
ttl
: cache's time-to-live (in milliseconds)
{
"plugins": [
{
"name": "command",
"args": {
"cmd": ["java", "Sample"],
"dir": "./mocks",
"prop": "api-key",
"section": "header",
"cache": true,
"ttl": 60000
}
}
],
"request": {
"method": "GET",
"path": "/command?header"
},
"response": {
"body": []
}
}
Request is a plugin to use request properties in response
-
headers:*header name*
: get any header from request -
url
: get full request url with query params. For example "http://localhost:3000/request/path?userName=John" -
path
: get only request path. For example "/request/path" -
query:*query param name*
: get any query param from request url
When using a non-existent header or query parameter, the replacement will not occur and the expression will remain as it is without changes.
{
"plugins": [
{ "name": "request" }
],
"request": {
"method": "GET",
"path": "/request/path?userName=John&kebab-case=value"
},
"response": {
"body": {
"accept": "#request:headers:accept#",
"undefined-header": "#request:headers:undefined-header#",
"url": "#request:url#",
"path": "#request:path#",
"userName": "#request:query:userName#",
"kebab-case": "#request:query:kebab-case#",
"undefined-query-param": "#request:query:undefined-query-param#"
}
}
}