Write the OpenAPI description of the membership service

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.

Local Server and Local Swagger Editor

Adapt the server code to CORS

In order to test a server described in OpenAPI using Swagger, some modifications need to be made to enable CORS.

  1. Check to see if the Flask CORS extension is installed (pip show flask_cors) and if not, install it (pip install flask_cors)
  2. Edit the Flask server from Activity 10 and add the following:

Now start the server.

Open the local Swagger editor

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)

Getting started

Clear the editor and start describing you service :

Test with the right-hand side interface.

Complete description

Add the specification for all routes :

Online (pythonanywhere) Server and Online Swagger Editor

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!