Take this scenario: You're always constructing apps that connects with different APIs, and sometimes you need to fake some data or use faked json to simulate your app behavior. You need to consider connection speed, response speed, the data which will be returned, etc.
So, i made a very simple local API using python and flask to test purposes. Its really simple implementation, and dont need database connections or lots of code (its python, dahrr). The API returns data on my http://localhost:5050/ and have some endpoints and a simple "s" url param to define the response time.
Clone the simple API from GitHub:
Now, assuming you already have Python installed, you must download Flask. I used Python 2.7 to write this script, but i bet you can easely run it using Python 3.
So, install Flask using pip or pip3 from your terminal:
pip install flask
Now, go to the Py-Simple-API folder on a terminal, and run "sh run"
Open your browser and go to http://localhost:5050/ and its done.
There are more 2 urls available by default:
A list of nobel prizes winners
A twitter API response example
The script looks for json data on the files stored at /data folder on the app root. So, just add a file on /data folder, and include a route on the api.py (just follow the example there) to have new addresses with your new json files.
You can pass your local IP as address too, then the data will be available thought your lan, depending of your configuration. Something like http://YourLocalIp:5050/
You can simply use the magic route /data/ like http://localhost:5050/data/json_name, where "json_name" is a name of any file in your Py-Simple-API/data/ folder. The API will return the file data as response. Dont use extensions, just the name. For example, we have the twitter.json there. To quickly return it, just go to http://localhost:5050/data/twitter.
Lets assume you have a json called cats.json with cat names. Then, you can move this file to Py-Simple-API/data/ folder, and in your browser you can go to http://localhost:5050/data/cats
If you need to test lacks of connection, response time, timeouts, etc, you can simple add a ?s=x at the end of your url, where x is the time in seconds that API must wait till the response. For example, if you want the API to wait 3 seconds before return the data stored on the twitter.json, just use the address http://localhost:5050/twitter?s=3 or http://localhost:5050/data/twitter?s=3
If you go to the cloned app root folder, you'll see some files.
api.py : Its the app per si. Its the place where all routes are defined, and the place you must include your new ones.
functions.py : Contains the functions (only one by now) used by api.py: a simple function to load a json file to a var.
run : The sh script used to start the API.
./data/ : The folder containing all the .json files which will be returned by the API.
This is a simple script writed by myself to test API responses, simulate lacks of time, etc, without starting by creating lots of Keys API key and More keys to integrate a thing that isnt exists yet. You just need a copy of a json response (or create a json by yourself) to simulate a lots of scenarios on your local machine. The hardest work here is maded by Flask. So, if you want to add advanced features or extend it, just take a look at Flask Doc: http://flask.pocoo.org/
Its not the target to build a real and robust API, just a simple and fast thing to test web apps behavior, hope you enjoy. Thats all folks!