Mock proposed API endpoints with stub.
I'm a lazy programmer. Basically, if you would tell me that I've to do the same task without applying my brain over and over again, I'll try to automate it with code (if I can xD)
The proposed API docs I write, have to be then mocked for APP / Front-End Developers so that they're not blocked by actual API calls. Later they can replace these stubs with actual API calls. With more requirements coming in, the proposed endpoint changes over time and the stubs have to be updated. I found myself in a viscous circle of keeping the both up to date which wastes my dev cycles (where I can work on generating actual endpoints) & thus created this small utility to help me.
Clone the repo & cd to it:
git clone https://github.com/CuriousLearner/API-stub-generator.git && cd API-stub-generator
Install pipenv
[sudo] pip install pipenv
Install all dependencies using pipenv
pipenv install
-
Run
pipenv run python serialize_data.pyto generate JSON file namedendpoints_data.json. Optionally, you can specify the path of the proposed endpoints docs using--file-pathoption like:pipenv run python serialize_data.py --file-path /pat/to/endpoints_data.json -
Run
pipenv run python create_mock_endpoints.pyto generateapp.pywith all the code for the Mocked end points. -
Run
pipenv run python app.py& hit any endpoint that you defined in theproposed_endpoints.mddoc.
- Avoiding the viscous circle of updating docs and stubs in three easy steps.
This script parses the proposed_endpoints.md file and generates a JSON file endpoints_data.json listing all the endpoints to be generated.
This script parses the JSON file endpoints_data.json and generates app.py file containing simple flask app with all the endpoints.
Just do a python app.py and your API endpoints are now live on http://localhost:5000