Skip to content

Instantly share code, notes, and snippets.

@giuliocalzolari
Last active July 2, 2024 14:56
Show Gist options
  • Save giuliocalzolari/3cc8933a16af5621ef9c80e6faf2874f to your computer and use it in GitHub Desktop.
Save giuliocalzolari/3cc8933a16af5621ef9c80e6faf2874f to your computer and use it in GitHub Desktop.
mockoon pagination example
{
"uuid": "fb2367f4-5a03-43f3-8ab7-f9581ea04ad5",
"lastMigration": 32,
"name": "Paginate",
"endpointPrefix": "",
"latency": 0,
"port": 3002,
"hostname": "",
"folders": [],
"routes": [
{
"uuid": "f51aa2ed-12c5-4424-9904-1f6a2e7623f6",
"type": "http",
"documentation": "",
"method": "get",
"endpoint": "items",
"responses": [
{
"uuid": "45323163-ebfa-48e2-a183-aad18f999dbc",
"body": "{{setVar 'page' (queryParam 'page' 1)}}\n{{setVar 'per_page' (queryParam 'per_page' 10)}}\n{{setVar 'total_pages' (ceil (divide (len (dataRaw 'items')) @per_page))}}\n{{setVar 'start' (multiply (subtract @page 1) @per_page)}}\n{{setVar 'end' (multiply @page @per_page)}}\n{{setVar 'data' (slice (dataRaw 'items') @start @end)}}\n{\n \"data\": [\n {{#each @data}}\n {\"id\": {{ this.id }},\"name\":\"{{ this.name }}\"}{{#unless @last}},{{/unless}}\n {{/each}}\n ],\n \"paging\": {\n \"page\": {{@page}},\n \"per_page\": {{@per_page}},\n \"next\": {{#if (lt @page @total_pages)}}\"/items?per_page={{ @per_page }}&page={{ add @page 1 }}\"{{else}}null{{/if}},\n \"previous\": {{#if (gt @page 1)}}\"/items?per_page={{ @per_page }}&page={{ subtract @page 1 }}\"{{else}}null{{/if}},\n \"total\": {{len (dataRaw 'items')}},\n \"total_pages\": {{ @total_pages }}\n }\n}\n",
"latency": 0,
"statusCode": 200,
"label": "",
"headers": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"bodyType": "INLINE",
"filePath": "",
"databucketID": "",
"sendFileAsBody": false,
"rules": [],
"rulesOperator": "OR",
"disableTemplating": false,
"fallbackTo404": false,
"default": true,
"crudKey": "id",
"callbacks": []
}
],
"responseMode": null
}
],
"rootChildren": [
{
"type": "route",
"uuid": "f51aa2ed-12c5-4424-9904-1f6a2e7623f6"
}
],
"proxyMode": false,
"proxyHost": "",
"proxyRemovePrefix": false,
"tlsOptions": {
"enabled": false,
"type": "CERT",
"pfxPath": "",
"certPath": "",
"keyPath": "",
"caPath": "",
"passphrase": ""
},
"cors": true,
"headers": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"proxyReqHeaders": [
{
"key": "",
"value": ""
}
],
"proxyResHeaders": [
{
"key": "",
"value": ""
}
],
"data": [
{
"uuid": "4f67b533-8c60-4c5b-a9ec-c714f8f886e7",
"id": "fd8m",
"name": "items",
"documentation": "",
"value": "[\n {{#repeat 1 50 comma=true}}\n { \"id\": {{@index}}, \"name\": \"{{ faker 'person.firstName' }}\" },\n {{/repeat}}\n]"
}
],
"callbacks": []
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment