Computer Science
Grade 9
20 min
REST APIs
REST APIs
Tutorial Preview
1
Introduction & Learning Objectives
Learning Objectives
Define what an API and a REST API are in the context of web development.
Explain the roles of a client and a server in an API interaction.
Identify the four most common HTTP methods (GET, POST, PUT, DELETE) and their purposes.
Read and interpret a simple JSON data structure.
Construct a basic API request URL (endpoint) to fetch data.
Describe how different applications use REST APIs to share information.
Ever wonder how your weather app gets the live forecast or how a game on your phone shows leaderboards from players around the world? 🤔 It's not magic, it's APIs!
In this lesson, we'll explore REST APIs, which are like secret messengers that let different software applications talk to each other. You'll learn how websites and apps sh...
2
Key Concepts & Vocabulary
TermDefinitionExample
API (Application Programming Interface)A set of rules and tools that allows one software application to talk to another. Think of it as a menu at a restaurant: it lists the dishes you can order (requests you can make) and describes what you'll get back.When you use a weather app, the app uses a weather service's API to ask for the current temperature in your city. The API defines how the app should ask for that information.
REST (Representational State Transfer)A popular style or architecture for designing APIs. REST APIs are known for being simple, reliable, and easy to use. They use standard web technologies, making them very common.Most modern web services, like those from YouTube, Twitter, or Google Maps, use REST APIs to let developers access their dat...
3
Core Syntax & Patterns
The Anatomy of a Request
Request = Endpoint + HTTP Method + (optional) Data
Every API request you make has two essential parts: the URL (Endpoint) you are targeting and the HTTP Method (the verb) you are using. For creating or updating data, you also include the data itself, usually in JSON format.
The Four Core HTTP Methods
GET: Read Data | POST: Create Data | PUT: Update Data | DELETE: Remove Data
These four verbs cover the most common operations you'll need. Think of them as CRUD (Create, Read, Update, Delete). Always choose the verb that matches the action you want to perform.
JSON Key-Value Pairs
`"key": value` (Keys are strings, values can be strings, numbers, booleans, etc.)
When sending or receiving data, it's almost always formatted in JS...
4 more steps in this tutorial
Sign up free to access the complete tutorial with worked examples and practice.
Sign Up Free to ContinueSample Practice Questions
Challenging
A developer sends a `GET` request to the `/users` endpoint and includes a JSON body `{"username": "newbie", "password": "1234"}` hoping to create a new user. The API returns an error. What is the fundamental mistake?
A.The JSON is formatted incorrectly.
B.The endpoint `/users` does not exist.
C.The developer used GET to try to create data, but GET is only for reading data.
D.The password '1234' is not secure enough.
Challenging
An API for an online store has an endpoint `/cart/items`. A client sends a request to this endpoint with a JSON body `{"productId": 7, "quantity": 1}`. The server adds the product to the cart. Why is POST a more appropriate method than PUT for this action?
A.POST is more secure than PUT for sending product IDs.
B.PUT can only be used to update the entire cart, not add one item.
C.POST is used to add a new resource to a collection, and the client doesn't know the final ID of the new cart item.
D.PUT requests are not allowed to have a JSON body.
Challenging
A user with ID 'sam123' has this data on the server: `{"username": "sam", "isActive": true, "level": 5}`. To update their status and level, which API request is the most complete and correct representation of a RESTful update?
A.POST to `/users` with body `{"username": "sam", "isActive": false, "level": 6}`
B.GET from `/users/sam123/update?isActive=false&level=6`
C.PUT to `/users/sam123` with body `{"username": "sam", "isActive": false, "level": 6}`
D.DELETE from `/users/sam123` and then POST to `/users`
Want to practice and check your answers?
Sign up to access all questions with instant feedback, explanations, and progress tracking.
Start Practicing Free