NGINX Modern Apps > Class 6 - NGINX API Management > Module 3 - Publish the API Source | Edit on
Step 5 - Update the API to v2.0¶
In the previous lab, we published version 1.0 of the API. As you noticed, the API Sentence application was not fully developed. The Colors
micro-service was not yet available.
The API Dev team has finally finished the Colors
micro-service app, and they want to push the app to the Kubernetes environment. They expect the DevOps team to publish this new version of the API Sentence app.
The API Dev team provided us a new version of the OAS spec file. This new version is available here: https://app.swaggerhub.com/apis/F5EMEASSA/API-Sentence/2.0
Note
You can notice a new PATH for Colors
Steps to publish version 2.0 of the API¶
Deploy the new Colors
micro-service in k8s¶
Let’s deploy the Colors
micro-service!
SSH (or WebSSH) to the
Docker (k3s + Rancher + ELK)
VMRun the following
kubectl
command in order to deploy theColors
micro-service and its k8s service:sudo su kubectl apply -f /home/ubuntu/k3s/attribut_add_colors.yaml -n api
Note
As you can notice, this micro-service is deployed in the same
NameSpace
as the otherWords
micro-services (api
)RDP to the
Win10
VM (user/user).Check in
Rancher
(admin/admin) that the newDeployment
has been successful (both theDeployment
andService
)- Click on the
Cluster Explorer
yellow button on the top right corner. - On the left menu, select
Deployments
. From here, you can see theDeployments
running in eachNameSpace
- Click on the
Open the
Edge Browser
, select theRandom Name Generator
bookmark, and check that the new micro-service is providing acolor
.
Warning
Why is the Frontend publishing the Colors
micro-service whereas the API Gateway is not yet configured with this new endpoint?
The reason is that the Frontend is directly connected to all k8s micro-services. This is an Front to Back
communication. Our NGINX API Gateway is publishing the API externally for other consumers (mobile app, partners…).
Update the API Definition to version 2.0¶
Connect to NGINX Controller, select your existing API Definition
api-sentence
, and clickEdit Version
:Select
OpenAPI Specification
->Copy and paste specification text
.Copy and paste the v2.0 OAS YAML content from https://app.swaggerhub.com/apis/F5EMEASSA/API-Sentence/2.0
Note
Note that the version of the API Definition did not change in the UI (it still shows as v1.0). This is a known bug, and will be fixed in the next release.
Click
Submit
Note
You should now see two more resources ->
Resources: 10
Update the Published API with the new Colors
endpoint¶
The
Colors
API endpoint is now known by our API Definition, let’s publish it!Select your existing API Definition
api-sentence-v1
, and click the edit button:In the
Routing
menu, you should now see the APIPaths
for theColors
endpoint.Click
Add New
to create a new component for theColors
micro-service.- Name:
cp-colors
- Click
Next
- In
Workload Groups
:- Name:
wl-colors
- In
Backend Workload URIs
: - URI:
http://10.1.20.8:31102
- Click
Done
- URI:
- In
- Click
Done
- Name:
- Click
Next
- Click
Submit
- Name:
Drag and drop the two new unrouted
Path
resources forColors
into thecp-colors
componentClick
Submit
Test the v2.0 API deployment¶
Steps:
RDP to the
Win10
VM (user/user).Open
Postman
and select theAPI Sentence Generator v1 and v2
collection.Send a request with the
GET Colors
call. The API Gateway will route the request to theColors
micro-service, and will return all the entries (all the words):[ { "id": 1, "name": "red" }, { "id": 2, "name": "blue" }, { "id": 3, "name": "green" }, { "name": "black", "id": 4 }, { "name": "yellow", "id": 5 } ]
Send a request with the
GET a Sentence from Generator
call. This request will ask thegenerator
to get one word per micro-service. As you can see, there is now a new entry forColors
:{ "adjectives": "calm", "animals": "whale", "colors": "yellow", "locations": "park" }
Note
The above entries will generate the sentence
calm whale of the yellow park
in theFrontend
application.
Warning
Congrats! You updated the published API to v2.0 with NGINX Controller and NGINX Plus as an API Gateway! As v2.0 does not break v1.0, we haven’t created a dedicated v2.0 published API. We simply updated v1.0.
In the next lab, we will update the API to v3.0, and this upgrade will break v2.0 as we will create a new parameter for an existing endpoint.