mock responses.. example
This commit is contained in:
6
example/mock/.local-web-server.json
Normal file
6
example/mock/.local-web-server.json
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"rewrite": [
|
||||
{ "from": "/tree", "to": "/mocks/trees.mock.js" },
|
||||
{ "from": "/tree/:id", "to": "/mocks/tree.mock.js" }
|
||||
]
|
||||
}
|
7
example/mock/css/style.css
Normal file
7
example/mock/css/style.css
Normal file
@ -0,0 +1,7 @@
|
||||
body {
|
||||
background-color: #AA3939;
|
||||
color: #FFE2E2
|
||||
}
|
||||
svg {
|
||||
fill: #000
|
||||
}
|
8
example/mock/index.html
Normal file
8
example/mock/index.html
Normal file
@ -0,0 +1,8 @@
|
||||
<head>
|
||||
<link rel="stylesheet" href="css/style.css">
|
||||
</head>
|
||||
<h1>Mock responses</h1>
|
||||
<ul>
|
||||
<li>list data</li>
|
||||
</ul>
|
||||
<script src="bundle.js"></script>
|
9
example/mock/index.js
Normal file
9
example/mock/index.js
Normal file
@ -0,0 +1,9 @@
|
||||
'use strict'
|
||||
const request = require('req-then')
|
||||
const $ = document.querySelector.bind(document)
|
||||
|
||||
request('http://localhost:8000/tree').then(response => {
|
||||
$('ul').innerHTML = JSON.parse(response.data).map(tree => {
|
||||
return `<li>${tree.name}</li>`
|
||||
}).join('')
|
||||
})
|
8
example/mock/mocks/tree.mock.js
Normal file
8
example/mock/mocks/tree.mock.js
Normal file
@ -0,0 +1,8 @@
|
||||
module.exports = [
|
||||
{
|
||||
response: {
|
||||
status: 200,
|
||||
body: { id: 2, name: 'eucalyptus', maxHeight: 210 }
|
||||
}
|
||||
}
|
||||
]
|
23
example/mock/mocks/trees.mock.js
Normal file
23
example/mock/mocks/trees.mock.js
Normal file
@ -0,0 +1,23 @@
|
||||
module.exports = [
|
||||
{
|
||||
request: {
|
||||
method: 'GET'
|
||||
},
|
||||
response: {
|
||||
status: 200,
|
||||
body: [
|
||||
{ id: 1, name: 'conifer', maxHeight: 115 },
|
||||
{ id: 2, name: 'eucalyptus', maxHeight: 210 }
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
request: {
|
||||
method: 'POST'
|
||||
},
|
||||
response: {
|
||||
status: 201,
|
||||
location: '/tree/1'
|
||||
}
|
||||
}
|
||||
]
|
Reference in New Issue
Block a user