0
0
Microservicessystem_design~10 mins

REST API between services in Microservices - Interactive Code Practice

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

Complete the code to define the HTTP method used to fetch data from another service.

Microservices
response = requests.[1]('http://service/api/data')
Drag options to blanks, or click blank then click option'
Aget
Bput
Cdelete
Dpost
Attempts:
3 left
💡 Hint
Common Mistakes
Using POST instead of GET to fetch data.
Confusing PUT with GET for data retrieval.
2fill in blank
medium

Complete the code to add a JSON payload when sending data to another service.

Microservices
response = requests.post('http://service/api/data', json=[1])
Drag options to blanks, or click blank then click option'
Adata
Bparams
Cheaders
Dpayload
Attempts:
3 left
💡 Hint
Common Mistakes
Passing headers or params instead of the actual data payload.
Using 'data' instead of 'payload' variable.
3fill in blank
hard

Fix the error in the code to correctly check if the response status code indicates success.

Microservices
if response.status_code == [1]:
    print('Success')
Drag options to blanks, or click blank then click option'
A404
B500
C200
D301
Attempts:
3 left
💡 Hint
Common Mistakes
Checking for 404 which means not found.
Using 500 which means server error.
4fill in blank
hard

Fill both blanks to correctly parse JSON data from the response and access the 'user' field.

Microservices
data = response.[1]()
user = data[2]'user')
Drag options to blanks, or click blank then click option'
Ajson
Btext
C['
D.get(
Attempts:
3 left
💡 Hint
Common Mistakes
Using response.text() instead of response.json().
Accessing dictionary keys with brackets without checking existence.
5fill in blank
hard

Fill all three blanks to build a REST API call with headers, query parameters, and handle the JSON response.

Microservices
headers = {'Authorization': 'Bearer [1]'}
params = {'id': [2]
response = requests.get('http://service/api/item', headers=headers, params=params)
data = response.[3]()
Drag options to blanks, or click blank then click option'
Atoken123
Bitem_id
Cjson
Dpayload
Attempts:
3 left
💡 Hint
Common Mistakes
Passing wrong variable names for headers or params.
Forgetting to parse JSON from response.