0
0
Nginxdevops~10 mins

API versioning with routing in Nginx - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to route requests to version 1 of the API.

Nginx
location /api/v1/ {
    proxy_pass http://backend[1];
}
Drag options to blanks, or click blank then click option'
A/v1
B/v1/
C/v2/
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting the trailing slash in proxy_pass causes incorrect URL forwarding.
Using the wrong version path in proxy_pass.
2fill in blank
medium

Complete the code to route requests to version 2 of the API.

Nginx
location /api/v2/ {
    proxy_pass http://backend[1];
}
Drag options to blanks, or click blank then click option'
A/v1/
B/v3/
C/v2/
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong version number in proxy_pass.
Missing the trailing slash in proxy_pass.
3fill in blank
hard

Fix the error in the location block to correctly route to version 1 API.

Nginx
location /api/v1 {
    proxy_pass http://backend[1];
}
Drag options to blanks, or click blank then click option'
A/v2/
B/v1
C/
D/v1/
Attempts:
3 left
💡 Hint
Common Mistakes
Missing trailing slash in location causes partial matching issues.
proxy_pass without trailing slash changes the forwarded URI.
4fill in blank
hard

Fill both blanks to route requests to version 3 API and set a custom header.

Nginx
location /api/v3/ {
    proxy_pass http://backend[1];
    proxy_set_header X-API-Version [2];
}
Drag options to blanks, or click blank then click option'
A/v3/
B"v3"
C"v2"
D/v2/
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong version path in proxy_pass.
Setting header without quotes causing syntax errors.
5fill in blank
hard

Fill all three blanks to create a map for API version routing and use it in proxy_pass.

Nginx
map $uri $backend_path {
    ~^/api/v1/ /v1/;
    ~^/api/v2/ /v2/;
    default [1];
}

location /api/ {
    proxy_pass http://backend[2];
    proxy_set_header X-API-Version [3];
}
Drag options to blanks, or click blank then click option'
A/v3/
B$backend_path
C"dynamic"
D/default/
Attempts:
3 left
💡 Hint
Common Mistakes
Not using the map variable in proxy_pass.
Incorrect default path causing routing errors.
Missing quotes around header value.