Welcome to our capstone unit! You've learned about clients, servers, HTTP requests, responses, APIs, and JSON. Now let's trace a complete API call from start to finish.
This will connect all the concepts you've learned into one clear example.
Engagement Message
Are you ready to see it all in action?
Let's imagine our app wants to get a random fact. It will use an API for this.
Step 1: The Request. Our app (the client) creates an HTTP GET
request and sends it to the API's specific URL, known as an endpoint.
For example, GET https://api.example.com/facts/random
.
Engagement Message
What do you think happens next?
Step 2: The Server's Work. The server at api.example.com
receives the request. It sees the GET
method and the /facts/random
path.
Its code then runs a function to find a random fact from its database.
Engagement Message
What do you think the server will do once it finds the fact?
Step 3: The Response. The server packages the fact into a JSON format. It then creates an HTTP response.
Because the request was successful, the server includes a 200 OK
status code. The JSON data is placed in the body of the response.
Engagement Message
