0
0
Rest APIprogramming~10 mins

204 No Content in Rest API - Interactive Code Practice

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

Complete the code to return a 204 No Content response in a REST API.

Rest API
return Response(status_code=[1])
Drag options to blanks, or click blank then click option'
A204
B200
C404
D500
Attempts:
3 left
💡 Hint
Common Mistakes
Using 200 OK instead of 204 No Content
Using 404 Not Found which means resource missing
Using 500 Internal Server Error which means server error
2fill in blank
medium

Complete the code to send a 204 No Content response without any body in a Flask API.

Rest API
from flask import make_response

response = make_response('', [1])
return response
Drag options to blanks, or click blank then click option'
A204
B201
C200
D400
Attempts:
3 left
💡 Hint
Common Mistakes
Sending a non-empty body with 204 status
Using 200 OK status code instead of 204
Using 201 Created which is for resource creation
3fill in blank
hard

Fix the error in this Express.js code to correctly send a 204 No Content response.

Rest API
app.delete('/item/:id', (req, res) => {
  // delete item logic
  res.status([1]).end();
});
Drag options to blanks, or click blank then click option'
A200
B500
C204
D404
Attempts:
3 left
💡 Hint
Common Mistakes
Sending a message body with 204 status
Using 200 OK status with a message body
Using 404 Not Found when item is deleted
4fill in blank
hard

Fill both blanks to create a 204 No Content response in FastAPI without a response body.

Rest API
from fastapi import FastAPI, Response

app = FastAPI()

@app.delete('/resource/{id}')
async def delete_resource(id: int):
    # deletion logic here
    return Response(status_code=[1], content=[2])
Drag options to blanks, or click blank then click option'
A204
B200
CNone
Db''
Attempts:
3 left
💡 Hint
Common Mistakes
Using None as content which causes errors
Using 200 status code instead of 204
Sending non-empty content with 204 status
5fill in blank
hard

Fill all three blanks to correctly return a 204 No Content response in Django REST Framework.

Rest API
from rest_framework.response import Response
from rest_framework import status

def delete_item(request, pk):
    # deletion logic
    return Response(status=[1], data=[2], content_type=[3])
Drag options to blanks, or click blank then click option'
Astatus.HTTP_204_NO_CONTENT
BNone
C'application/json'
D{}
Attempts:
3 left
💡 Hint
Common Mistakes
Sending data with 204 status
Using raw 204 integer instead of status constant
Omitting content_type or using wrong type