Bird
Raised Fist0
HLDsystem_design~10 mins

REST API best practices in HLD - Interactive Code Practice

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

Complete the code to specify the HTTP method used to retrieve data in a REST API.

HLD
Use the [1] method to fetch resources in REST APIs.
Drag options to blanks, or click blank then click option'
APUT
BPOST
CDELETE
DGET
Attempts:
3 left
💡 Hint
Common Mistakes
Using POST instead of GET to retrieve data.
Confusing GET with DELETE or PUT methods.
2fill in blank
medium

Complete the code to indicate the recommended format for REST API responses.

HLD
REST APIs should return data in [1] format for easy parsing.
Drag options to blanks, or click blank then click option'
AXML
BJSON
CHTML
DCSV
Attempts:
3 left
💡 Hint
Common Mistakes
Using XML which is more verbose and less preferred.
Returning HTML which is for web pages, not API data.
3fill in blank
hard

Fix the error in the REST API URL design to follow best practices.

HLD
The URL to get a user by ID should be '/api/users/[1]' instead of '/api/getUser?id=[1]'.
Drag options to blanks, or click blank then click option'
AuserId
B{id}
C:id
Did
Attempts:
3 left
💡 Hint
Common Mistakes
Using query parameters instead of path parameters for resource IDs.
Using curly braces '{}' which are not standard in URLs.
4fill in blank
hard

Fill both blanks to correctly implement pagination parameters in a REST API endpoint.

HLD
GET /api/items?[1]=10&[2]=2
Drag options to blanks, or click blank then click option'
Alimit
Boffset
Cpage
Dsize
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing 'offset' with 'page' parameters.
Using 'size' instead of 'limit' which is less common.
5fill in blank
hard

Fill all three blanks to correctly set HTTP status codes for REST API responses.

HLD
Return status [1] for a successful GET, [2] when a resource is created, and [3] when a resource is not found.
Drag options to blanks, or click blank then click option'
A200
B201
C404
D500
Attempts:
3 left
💡 Hint
Common Mistakes
Using 500 for client errors instead of server errors.
Mixing up 404 and 400 status codes.

Practice

(1/5)
1. Which HTTP method is typically used to update an existing resource in a REST API?
easy
A. PUT
B. GET
C. POST
D. DELETE

Solution

  1. Step 1: Understand HTTP methods for REST

    GET retrieves data, POST creates new resources, PUT updates existing resources, DELETE removes resources.
  2. Step 2: Identify method for updating

    PUT is the standard method to update or replace an existing resource in REST APIs.
  3. Final Answer:

    PUT -> Option A
  4. Quick Check:

    Update = PUT [OK]
Hint: Update resource? Think PUT method [OK]
Common Mistakes:
  • Confusing POST with update instead of create
  • Using GET for updates
  • Using DELETE to update
2. Which of the following is the correct way to version a REST API in the URL?
easy
A. /v1/api/resource
B. /api/resource/v1
C. /api/v1/resource
D. /api/resource?version=1

Solution

  1. Step 1: Understand common versioning patterns

    Versioning is often done in the URL path to clearly separate API versions.
  2. Step 2: Identify correct version placement

    Placing version immediately after the base API path, like /api/v1/resource, is standard practice.
  3. Final Answer:

    /api/v1/resource -> Option C
  4. Quick Check:

    Version in path = /api/v1/ [OK]
Hint: Version goes right after /api/ in URL path [OK]
Common Mistakes:
  • Putting version after resource name
  • Using query parameters for versioning
  • Placing version before /api/
3. Given the following API response status codes, which one indicates a successful resource creation?
{
  "status": 201,
  "message": "Created"
}
medium
A. 200 OK
B. 201 Created
C. 400 Bad Request
D. 404 Not Found

Solution

  1. Step 1: Review HTTP status codes for success

    200 means success for general requests, 201 means resource created successfully.
  2. Step 2: Match status code to creation

    201 Created is the correct code to indicate a new resource was successfully created.
  3. Final Answer:

    201 Created -> Option B
  4. Quick Check:

    Creation success = 201 [OK]
Hint: 201 means resource created successfully [OK]
Common Mistakes:
  • Confusing 200 with creation success
  • Using 400 or 404 for success
  • Ignoring status code meaning
4. A developer designed a REST API endpoint as POST /users/delete to delete a user. What is the best fix to follow REST API best practices?
medium
A. Change to GET /users/delete
B. Keep POST /users/delete but add a query param
C. Use PUT /users/delete
D. Change to DELETE /users/{id}

Solution

  1. Step 1: Identify correct HTTP method for deletion

    DELETE method is the standard for removing resources in REST APIs.
  2. Step 2: Correct endpoint structure

    Use resource identifier in URL path like /users/{id} with DELETE method for clarity and REST compliance.
  3. Final Answer:

    Change to DELETE /users/{id} -> Option D
  4. Quick Check:

    Delete resource = DELETE /resource/{id} [OK]
Hint: Use DELETE method with resource ID in URL [OK]
Common Mistakes:
  • Using POST for delete actions
  • Using GET to delete resources
  • Adding delete action in URL path
5. You want to design a REST API that returns a list of products with optional filtering by category and price range. Which approach follows REST API best practices?
hard
A. GET /products?category=electronics&min_price=100&max_price=500
B. POST /products/filter with JSON body containing filters
C. GET /products/filter/category/electronics/price/100-500
D. PUT /products with filter parameters in the body

Solution

  1. Step 1: Understand filtering in REST APIs

    Filtering is best done using query parameters in GET requests to keep APIs simple and cacheable.
  2. Step 2: Evaluate options for filtering

    GET /products?category=electronics&min_price=100&max_price=500 uses GET with query parameters, which is standard and clear. Other options misuse POST or PUT or complex URL paths.
  3. Final Answer:

    GET /products?category=electronics&min_price=100&max_price=500 -> Option A
  4. Quick Check:

    Filter with GET query params [OK]
Hint: Use GET with query parameters for filtering [OK]
Common Mistakes:
  • Using POST or PUT for filtering
  • Embedding filters in URL path segments
  • Sending filters in request body for GET
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard