Computer Science Grade 10 20 min

3. Understanding API Endpoints and Requests

Learn about API endpoints and how to make requests to retrieve data.

Tutorial Preview

1

Introduction & Learning Objectives

Learning Objectives Define what an API endpoint is and explain its role in client-server communication. Differentiate between the components of a URL: protocol, domain, path, and query parameters. Explain the purpose of the two most common HTTP request methods: GET and POST. Construct a valid GET request URL, including query parameters, to retrieve specific data. Interpret a simple JSON response from an API, identifying keys and values. Use hypothetical API documentation to identify the correct endpoint for a given task. Ever wonder how your weather app instantly knows the temperature in your city or how a game displays live scores? 🌦️ It's not magic; it's your app making a request to an API endpoint! Think of an API as a restaurant menu for a program. This lesson...
2

Key Concepts & Vocabulary

TermDefinitionExample API EndpointA specific URL (Uniform Resource Locator) where an API can be accessed. Each endpoint corresponds to a specific function or data resource.In a weather API, `https://api.weather.com/v1/current?city=Toronto` is an endpoint to get the current weather for Toronto. RequestA message sent from a client (like your browser or an application) to a server, asking for data or to perform an action.Your browser sending a request to `https://api.example.com/users/123` to fetch information about user 123. ResponseThe message a server sends back to the client after receiving a request. It contains the requested data (e.g., in JSON format) or a status code indicating success or failure.The server sending back `{"id": 123, "name": "Alex"}` afte...
3

Core Syntax & Patterns

Anatomy of a URL Endpoint protocol://domain/path?key1=value1&key2=value2 This is the fundamental structure of a web request. `protocol` is http/https. `domain` is the server name. `path` specifies the resource. `?` starts the query parameters, which are key-value pairs separated by `&`. GET Request Pattern GET /path/resource?filter=value Use the GET method to retrieve data from a server. All required information, like filters or identifiers, is placed directly in the URL's path or query parameters. This method is for reading data only. POST Request Pattern POST /path/resource Use the POST method to send data to a server to create a new resource (e.g., posting a comment, creating a user). The data (like a JSON object) is sent in the 'body' of th...

4 more steps in this tutorial

Sign up free to access the complete tutorial with worked examples and practice.

Sign Up Free to Continue

Sample Practice Questions

Challenging
An API request to `https://api.example.com/search?q=apple&sort=price&q=iphone` fails. What is the most likely reason for this failure based on standard API conventions?
A.The API does not support sorting by 'price'.
B.The query parameter 'q' is used twice with different values, which can be ambiguous or unsupported by the server.
C.The value 'iphone' is not a valid search term.
D.The protocol should be 'http' instead of 'https'.
Challenging
You are designing an API for a university's course catalog. You need to provide a way to (1) retrieve a list of all courses in the 'Computer Science' department and (2) allow administrators to add a new course. Which pair of endpoints and methods is the most logical and conventional design?
A.1) `POST /courses?dept=CS` and 2) `GET /new_course`
B.1) `GET /courses?department=Computer+Science` and 2) `POST /courses`
C.1) `GET /ComputerScience/courses` and 2) `GET /courses/add`
D.1) `POST /get_courses` and 2) `POST /add_course`
Challenging
A client makes a GET request to `https://api.weather.com/forecast?city=Tokyo`. To add a new weather station in Tokyo to the database, which of the following changes is the MOST critical and fundamental?
A.Changing the HTTP method from GET to POST and sending the new station's data in the request body.
B.Changing the query parameter from `city=Tokyo` to `new_station=Tokyo`.
C.Changing the path from `/forecast` to `/add_station`.
D.Adding a new query parameter, such as `&action=add`.

Want to practice and check your answers?

Sign up to access all questions with instant feedback, explanations, and progress tracking.

Start Practicing Free

More from IV. Interacting with APIs: Data on Demand

Ready to find your learning gaps?

Take a free diagnostic test and get a personalized learning plan in minutes.