I am building a library that makes calls to a server that returns JSON. I'd like to be able to test this library. This would require my testing code to make a call to a working server that returns JSON. Does anyone know of a server that is suitable for this purpose?
A common use of JSON is to exchange data to/from a web server. When receiving data from a web server, the data is always a string. Parse the data with JSON.
Use npx to solve the error "json-server is not recognized as an internal or external command, operable program or batch file", e.g. npx json-server --watch db. json or install the package globally by running npm install -g json-server . The fastest way to solve the error is to use the npx command.
We just need to use the --port number flag. For example: json-server --watch db. json --port 3004.
There is a great server located at http://echo.jsontest.com that does precisely this. You can even determine the output by changing the URI you call.
For example, the http://echo.jsontest.com/key/value URI returns this:
{"key": "value"}
And the http://echo.jsontest.com/key/value/otherkey/othervalue URI returns:
{
"otherkey": "othervalue",
"key": "value"
}
The server is also very fast, ideal for testing purposes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With