Bird
Raised Fist0
Rest APIprogramming~10 mins

Search parameter in Rest API - Interactive Code Practice

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

Complete the code to add a search parameter to the API endpoint URL.

Rest API
url = "https://api.example.com/items?[1]=book"
Drag options to blanks, or click blank then click option'
Aquery
Bfilter
Csort
Dsearch
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'filter' or 'query' which may not be recognized by this API.
2fill in blank
medium

Complete the code to extract the search parameter value from the URL query string.

Rest API
search_term = request.args.get('[1]')
Drag options to blanks, or click blank then click option'
Asearch
Bfilter
Cquery
Dterm
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different parameter name that does not match the URL.
3fill in blank
hard

Fix the error in the code to correctly check if the search parameter exists.

Rest API
if '[1]' in request.args:
Drag options to blanks, or click blank then click option'
Aquery
Bterm
Csearch
Dfilter
Attempts:
3 left
💡 Hint
Common Mistakes
Checking for wrong parameter names like 'term' or 'filter'.
4fill in blank
hard

Fill both blanks to build a URL with search and sort parameters.

Rest API
url = f"https://api.example.com/items?[1]=phone&[2]=asc"
Drag options to blanks, or click blank then click option'
Asearch
Bfilter
Csort
Dorder
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'filter' instead of 'search' or 'order' instead of 'sort'.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension filtering items by search term length and sorting by price.

Rest API
filtered = {item['name']: item['price'] for item in items if len(item['name']) [1] [2] and item['price'] [3] 100}
Drag options to blanks, or click blank then click option'
A>
B3
C<=
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong comparison operators or values that don't filter correctly.

Practice

(1/5)
1.

What is the main purpose of a search parameter in a REST API URL?

easy
A. To change the API server address
B. To filter the data returned by the API
C. To add security to the API
D. To format the API response as XML

Solution

  1. Step 1: Understand what search parameters do

    Search parameters are added to the URL to specify what data you want from the API.
  2. Step 2: Identify the purpose of filtering

    Filtering means selecting only the data that matches your criteria, which is what search parameters do.
  3. Final Answer:

    To filter the data returned by the API -> Option B
  4. Quick Check:

    Search parameter = filter data [OK]
Hint: Search parameters filter data in API URLs [OK]
Common Mistakes:
  • Thinking search parameters change server address
  • Confusing search parameters with security tokens
  • Assuming search parameters format response
2.

Which of the following is the correct way to add a search parameter named name with value alice to a REST API URL?

https://api.example.com/users
easy
A. https://api.example.com/users#name=alice
B. https://api.example.com/users/name=alice
C. https://api.example.com/users?name=alice
D. https://api.example.com/users&name=alice

Solution

  1. Step 1: Recall the syntax for search parameters

    Search parameters start with a question mark (?) after the base URL.
  2. Step 2: Check the correct separator and format

    The parameter is added as ?name=alice. Using & or # or slashes is incorrect here.
  3. Final Answer:

    https://api.example.com/users?name=alice -> Option C
  4. Quick Check:

    Use ? before first parameter [OK]
Hint: First parameter starts with ? in URL [OK]
Common Mistakes:
  • Using & instead of ? for first parameter
  • Using # which is for anchors, not parameters
  • Adding parameters as path segments
3.

What will be the full URL to search for users with age 30 and city as NY?

Base URL: https://api.example.com/users
medium
A. https://api.example.com/users?age=30&city=NY
B. https://api.example.com/users?age=30?city=NY
C. https://api.example.com/users&age=30&city=NY
D. https://api.example.com/users#age=30&city=NY

Solution

  1. Step 1: Add first parameter with ?

    The first search parameter starts with a question mark: ?age=30.
  2. Step 2: Add second parameter with &

    Additional parameters use & to separate: &city=NY.
  3. Final Answer:

    https://api.example.com/users?age=30&city=NY -> Option A
  4. Quick Check:

    First ? then & for multiple parameters [OK]
Hint: Use ? for first, & for others in URL [OK]
Common Mistakes:
  • Using ? for every parameter
  • Using & before first parameter
  • Using # which is for anchors
4.

Identify the error in this URL with search parameters:

https://api.example.com/products?category=books&price=20?sort=asc
medium
A. Using two question marks (?) for parameters
B. Missing & between parameters
C. Using = instead of : in parameters
D. Parameters should be in the URL path, not query

Solution

  1. Step 1: Check parameter separators

    Only the first parameter uses ?, others must use &.
  2. Step 2: Identify the error in the URL

    The URL incorrectly uses a second ? before sort=asc instead of &.
  3. Final Answer:

    Using two question marks (?) for parameters -> Option A
  4. Quick Check:

    Only one ? allowed, others use & [OK]
Hint: Only one ? in URL, then & for others [OK]
Common Mistakes:
  • Using multiple ? instead of &
  • Confusing = with : in parameters
  • Thinking parameters belong in URL path
5.

You want to search a REST API for books with author as John and year greater than 2010. Which URL correctly uses search parameters to do this?

hard
A. https://api.example.com/books?author=John&year>2010
B. https://api.example.com/books?author=John&year=2010>
C. https://api.example.com/books?author=John&year=gt2010
D. https://api.example.com/books?author=John&year_gt=2010

Solution

  1. Step 1: Understand how to express 'greater than' in search parameters

    REST APIs often use suffixes like _gt for 'greater than' in parameters.
  2. Step 2: Check each option for correct syntax

    https://api.example.com/books?author=John&year_gt=2010 uses year_gt=2010, which is a common and correct way to express this filter.
  3. Final Answer:

    https://api.example.com/books?author=John&year_gt=2010 -> Option D
  4. Quick Check:

    Use _gt suffix for greater than filters [OK]
Hint: Use _gt suffix for 'greater than' in parameters [OK]
Common Mistakes:
  • Using > directly in URL parameter
  • Placing operators after values
  • Confusing parameter syntax for filters
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