Up to now, a client that wishes to use our API to update information about a member needs to ask us about the path to use, the format of data to provide etc. Let's describe the interface of our service using the OpenAPI standard: we specify the requests our server responds to, the expected parameters, and describe the results returned to the client. We use the Swagger editor to assist us in setting up this document.
In order to test a server described in OpenAPI using Swagger, some modifications need to be made to enable CORS.
pip show flask_cors
) and if not, install it (pip install flask_cors
)from flask_cors import CORS
CORS(app)
right after the line app = Flask("association")
Now start the server.
The online Swagger editor cannot access you local server so we used a locally installed version instead. Open the Swagger Editor installed locally: file:///home/abc/swagger-editor-master/index.html (Note: if you're not using the provided Docker image, you need to download and unzip Swagger)
Clear the editor and start describing you service :
Test with the right-hand side interface.
Add the specification for all routes :
/members/{ln}
/membersInRange?minAge=X&maxAge=Y
/members
/members/{ln}
/members
/members/{ln}
/members/{ln}
Go to pythonanywhere, add the 2 lines about CORS to your python code from Activity 10, open a console and install flask_cors, and run the new version of the server.
Go to the online Swagger editor, clear the editor and paste the YAML description written previously. Change the url
line to https://yourpythonanywhereusername.eu.pythonanywhere.com. Try it out!