Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/samvloeberghs/api-stub-server
This project serves as an example to define an API stub server. It's a work in progress and will provide some more exhaustive examples to use the full potential of nodeRed.
https://github.com/samvloeberghs/api-stub-server
Last synced: 21 days ago
JSON representation
This project serves as an example to define an API stub server. It's a work in progress and will provide some more exhaustive examples to use the full potential of nodeRed.
- Host: GitHub
- URL: https://github.com/samvloeberghs/api-stub-server
- Owner: samvloeberghs
- Created: 2015-11-06T14:02:38.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2015-11-06T14:06:56.000Z (about 9 years ago)
- Last Synced: 2024-04-09T14:59:42.219Z (9 months ago)
- Language: JavaScript
- Homepage: https://github.com/samvloeberghs/api-stub-server
- Size: 0 Bytes
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# API stub server
This code has the purpose to be an example project to setup a stub server for any API.
## Prerequisites
You should have node, npm & git installed. You can check this in cli:
```
node -v && npm -v && git --version
```## Running the stub server
1. Clone the project
2. Run `npm install`
3. Run the server: `npm run api`
4. Open up the graphical interface: [http://localhost:1880](http://localhost:1880)**Username**: nodered
**Password**: password## Documentation
This project uses the great NodeRED. So special thanks to the IBM guys working on it. You can find some more info
about the tool using the following- NodeRED website: http://nodered.org/
- Documentation: http://nodered.org/docs/
- Github: https://github.com/node-red/node-red## Accessing endpoints
To quickly setup this project and checkout the examples I suggest you to install Postman.
You can use the examples provided as a Postman export. Just import the `api-stub-server.postman_collection.json` file
in your postman setup.It is defined as a collection with the same name as this project.
## Examples
You can always run the API stub server by doing this commands:
```
npm run api
```### Creating different endpoints
This example shows how to create several endpoints. Load it by going to tab "endpoints" in the canvas. It might be
useful to check the impact of a slow API on your application. In the canvas you can see the function `Random delay 1-3s`
that slows down the request.You can implement the various HTTP methods POST, GET, PUT & DELETE The examples provided won't do actual writing in
any DB. It just shows the possibilities. Check it out by using the `News overview`, `News detail GET`,
`News detail PUT` & `News overview POST` examples in the Postman export.### Enable debug logging
This example shows how to have a toggle in NodeRED to disable or enable debug loggin on runtime. Load it by going to tab
"debug logging" in the canvas. In the canvas you will have an injector to enable or disable. Try playing around with
the toggle. You can do this by starting the `FAQ overview` request in the postman example.This is just an example on how to enable debugging based on the request. You can basically output anything that is
related to the request or response in your debug function.### Differentiating the responses from an endpoint (1)
It's possible to differentiate between the responses coming back from the same API. This might be usefull when you want
to test an endpoint that might have different structure based on some environment setting. For example a logged in user
versus a guest user.Enable the guest user by clicking in front of the inject node with the name "Guest User". Try the same for the
authenticated user by injecting it. When you do a call the `search/result` endpoint you will see that it differs.### Differentiating the responses from an endpoint (2)
This example is quite similar to the previous one. Instead of using a switch in NodeRed we control it via the Headers in
the request. Again, you can use the /search/result endpoint for this example.Try now to disable or enable the X-Application-User-Type header in the `search/result` endpoint and issue the request.
Possible values are 'bizz' or 'res'. If another provided it will default to 'res'.## Contributors
Sam Vloeberghs - [@samvloeberghs](https://twitter.com/samvloeberghs) - [[email protected]](mailto:[email protected])