This is the template for creating APIs locally and deployed on Kubernetes & Istio.
Dockerfile: running the service just do adocker rundocker-compose.yml: starts your development setup including the swagger editor as well as a mock server based on theswagger.yamlfile located in/swagger/ directory/api: including the python modules for the api implementation (described in the sections below)/lib: includes currently only the library which implements a customer token validation./devops: includes the script to build and deploy and the istio config
You either can work with the Dockerfile which includes all the commands to start the server or you develop locally. I suggest you use skaffold - the installation instructions you find using the link.
- Create your swagger file including examples (they are used for the mock) and place it under
/swagger/swagger.yaml - Setup your environment by doing
virtualenv venv --python=python3
source venv/bin/activate
# install pylint
pip install pylint
pip install -r requirements.txtIf you use visual studio code do this first in your terminal window and then open the folder again with code ..
- Then start the connxion mock server based on the swagger file:
connexion run swagger/swagger.yaml --mock=all - Validate this with your customers like external API developers and your frontend developer and improve the API.
- Then implement the API resources and methods under
api.
- Check that you have have a local docker environment in Plattform -> Setup Docker Environment.
- Create Dockerfile and docker-compose that starts the Mock Server(Code) - make sure the Swagger file does not include custom functions like
x-tokenInfoFunc. TODO create it for the mock - Implement Frontend against mocks
- Update Dockerfile to production config
- Implement API (including DB, ...)
Connexion Examples:
- https://github.com/hjacobs/connexion-example
- https://github.com/ssola/python-flask-microservice
- http://blog.bejanalex.com/2017/03/mongodb-rest-api-interface-in-docker/
Create a client library for the API:
Use Feature flags:
Python Testing:
- Unit Testing
- Mocks
- Code Coverage
Python Functional Programming:
Python Clean Code:
- http://pythonforengineers.com/writing-great-code/
- https://github.com/zedr/clean-code-python
- https://github.com/rmariano/Clean-code-in-Python/blob/master/build/Clean code in Python.pdf
- http://docs.python-guide.org/en/latest/writing/reading/
Benefits API First:
http://connexion.readthedocs.io/en/latest/cli.html
https://blog.runscope.com/posts/openapi-swagger-resource-list-for-api-developers
https://github.com/zalando/connexion
https://cidrblock.github.io/zero-to-api-in-4-minutes.html
Beispiel: https://github.com/hjacobs/connexion-example
Get started with Connextion: http://connexion.readthedocs.io/en/latest/quickstart.html
https://github.com/zalando/connexion
https://github.com/hjacobs/connexion-example
https://cidrblock.github.io/zero-to-api-in-4-minutes.html
https://github.com/ssola/python-flask-microservice/blob/master/api/room.py
https://medium.com/@ssola/building-microservices-with-python-part-i-5240a8dcc2fb
http://coderobot.downley.net/swagger-driven-testing-in-python.html
https://uwsgi-docs.readthedocs.io/en/latest/
http://connexion.readthedocs.io/en/latest/routing.html
- https://medium.com/@ssola/building-microservices-with-python-part-i-5240a8dcc2fb
- https://github.com/hjacobs/connexion-example/blob/master/app.py
- http://connexion.readthedocs.io/en/latest/request.html
- Check a token: https://auth0.com/docs/api-auth/tutorials/verify-access-token
API Sources / public api collection: https://any-api.com
https://www.programmableweb.com/apis/directory
https://apis.guru/browse-apis/
It is suggested to use the docker container for your deployment using the container runtime of your choice.
We save the environment config:
# config for mongodb
export MONGODB_URL= mongodb://sampleUser:samplePassword@localhost:27017/identities // mongodb://mongodb:27017/test
export MONGODB_USERNAME=sampleUser
export MONGODB_PASSWORD=samplePassword
export MONGODB_ROOT_PASSWORD=samplePassword
# config apigee
export apigee_client_id=user@sample.com
export apigee_client_secret=samplePassword
export apigee_management_endpoint=https://api.enterprise.apigee.com/v1/organizations/denseidel-trial
export apigee_auth_endpoint=https://login.apigee.com/oauth/token
#config auth0
export auth_client_id=dsfdfndfernd34fdfn3234djfdf
export auth_client_secret=ldfjn3f3o23nf23lfj0j23fn2lfn23nf232nf23nf2nfn32fn2ffn2
export auth0_endpoint=https://d10l.eu.auth0.com
Connect to Istio MongoDB with port forwarding
kubectl -n default port-forward \
$(kubectl -n default get pod -l app=mongodb -o jsonpath='{.items[0].metadata.name}') \
27017:27017 &

