The workshop has 4 parts:
- Intro to REST API development, using Node.js
- Intro to API specification with Swagger
- API deployment in Azure, with Azure Web Apps
- Deploying the API to Azure API Management
Link to slides: https://oyron.github.io/edc-api-slides/
- Node.js installed
- Postman Installed
- Data Platform Developer role in AccessIT
See getting started info.
Use branch part1
. Run the server: nodemon server.js
.
Make sure the server is running by accessing http://localhost:3000
The Library API
The API should support the operations listed below. The API should use JSON as data format. Operations taking id as input parameter should return a client error status code (4xx) with a message if the id does not exist. Other types of input validation is not required.
- Get all books. Return a list of books. Already implemented.
- Get an existing book (by id). Return the requested book.
- Add a new book. Return the created book.
- Update an existing book (by id). Return the updated book.
- Delete a book (by id). Return nothing.
Use Postman for testing. Import the collection file in the postman
folder into Postman.
Relevant HTTP methods:
- GET
- POST
- PUT
- DELETE
Relevant HTTP status codes:
- 200 OK
- 201 Created (should include Location response header)
- 204 No content
- 400 Bad request
- 404 Not found
- 500 Internal Server Error
For more details, see: https://restfulapi.net/http-status-codes/
Use https://editor.swagger.io/
Or run locally using Docker: docker run -p 8080:8080 --name swagger-editor swaggerapi/swagger-editor
Either keep working on branch part1
and only load the Swagger skeleton file from branch part2
, by
running: git checkout origin/part2 -- src/oas/swagger.yaml
, or replace your work from part 1 and load a complete API and Swagger skeleton, by switching to branch part2
.
- Open the skeleton Swagger file
src/oas/swagger.yaml
in the editor. - Add the missing endpoints to the Swagger file. Make sure the yaml is valid.
- Test running the endpoints from the Swagger editor.
Swagger specification: https://swagger.io/specification/v2/
From Swagger Editor
Select Generate Client -> html2. Unzip and place in folder src/static/api-docs
Browse the generated documentation.
(Optional) With Docker, Using OpenAPI Generator
Run the following command from the src
directory:
docker run --rm -v ${PWD}:/local openapitools/openapi-generator-cli generate \
-i /local/oas/openapi.yaml \
-g html \
-o /local/static/api-docs/openapi-generator
In this part we will deploy our Library API to Azure.
Continue working on your current branch, or switch to branch master
to load a completed Swagger file and API.
Deployment Procedure:
- Create Azure Web App using the Azure portal: https://portal.azure.com
- App name: library-
- Subscription: VanDamme
- Resource Group (Use Existing): APIWorkshop
- OS: Linux
- App Service Plan - Create new:
- Location: North Europe
- Pricing Tier: B1 (free)
- Runtime Stack: Node.js 10.1
-
Select deployment options -> Choose source -> Local Git Repository
-
Set Deployment Credentials
-
Add an Azure remote to local Git repo:
git remote add azure <url>
-
Try accessing the Web App URL. You should get the message: "Your App Service app is up and running"
-
Deploy:
git push azure master
-
Test accessing the API.
-
Check the content of the server log by opening the SSH console in the Azure portal, and viewing
/home/site/wwwroot/src/log/server.log
In this task we will add our API to Azure API Management.
-
Edit
swagger.yaml
in the Swagger editor and make the URL refer to your newly created service in Azure. Also changescheme
tohttps
. Export the file as JSON (APIM currently does not support YAML). -
Add your API in the Azure portal
- Create new API from OpenAPI Specification. Select the
swagger.json
file. - Display name: EDC API <user name>, e.g. EDC API OYRON
- Name: edc-api-<user name>, e.g. edc-api-oyron
- API URL Suffix: same as name (edc-api-<user name>)
-
After creating the API, go to settings, add "EDC API Workshop" as a product
-
Verify that you are able to call the API through APIM by using Postman (make sure you are accessing the APIM Url)