Glossary
Last Updated Jul 18, 2023

API Request

Emma Jagger
Emma Jagger

Table of Contents:

Get your free
 API key now
stars rating
4.8 from 1,863 votes
See why the best developers build on Abstract
START FOR FREE
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
No credit card required

What is an API Request?  

In a REST API, a request is issued by a client to a server. A client makes a request to an API at an endpoint which it has access to. The API validates the request and passes the request to the destination server or program. The server sends a response back, first through the API, which then transfers it back to the client. The request is usually packaged in a JSON (JavaScript Object Notation) file. JSON is ubiquitous because it's lightweight and easy to read, but it's not a required format.  

What Can an API Request Do?

A client can issue different kinds of requests, of which there are four main types:

  • GET - This request reads information from a record in the database
  • PUT- This request changes a record’s information in the database
  • POST - This request creates a new record in the database
  • DELETE - This request removes a record from the database.  

An API request isn't always just asking for something, but to perform an action, like adding or modifying data on a server accessed through an API. REST provides an architecture for HTTP clients and servers to understand and process these requests.

What is in an API Request?  

A request might look like this:


fetch('https://jsonplaceholder.typicode.com/todos/1')
  .then(response => response.json())
  .then(json => console.log(json))

This request goes to the URL `https://jsonplaceholder.typicode.com/` at the API endpoint `todos/1`. The server receives these instructions at the endpoint, and returns a JSON with the requested information from the server:


{
	"userId": 1,
	"id": 1,
	"title": "delectus aut autem",
	"completed": false
}

So what is happening here? The client requested ("fetched") information from the API URI at `https://jsonplaceholder.typicode.com/`, specifically the endpoint at `todos/1` by sending  its request to the API. The API authenticates the request and makes a call to the server. The server returns the requested information to the API, and the API sends a JSON card in return with the requested information back to the client.  

API Authentication and Query Parameters

This request doesn't include an authentication key, which is usually issued by the API provider for security purposes. It also has no query parameters, which are attached to the end of a URL and separated from the URL by a question mark (?). For example, in a request to the Currency Exchange Rate API, the currency to convert to and from, as well as the amount, sent from the user to the API would be a query parameter.  

Conclusion

API requests operate within REST architecture, providing a structured way for developers to communicate with remote resources through endpoints. This structure makes REST APIs popular, easy to use, and also secure. APIs[let you open up access to your resources while maintaining security and control.

Frequently Asked Questions

What is an API request?

An API request is a message a client sends to a server through an API to read data or perform an action, such as adding or modifying data. In a REST API, the client sends the request to an endpoint it has access to, and the data is usually packaged in JSON format.

How does an API request work?

The client sends a request to an API endpoint, and the API validates it and passes it to the destination server or program. The server then sends a response back through the API, which transfers it to the client.

What is included in an API request?

An API request typically includes an HTTP method that states the action to perform, and an endpoint URL that points to the specific resource. It may also include an authentication key and query parameters, depending on the API.

What are the main HTTP methods used in an API request?

The four main HTTP methods are GET, POST, PUT, and DELETE. GET reads information from a record, POST creates a new record, PUT modifies an existing record, and DELETE removes a record.

What is the difference between an API request and an API response?

An API request is the message the client sends to the server to ask for data or to perform an action. The API response is what the server sends back through the API to the client, usually containing the requested data in JSON.

What are query parameters in an API request?

Query parameters are values attached to the end of a URL and separated from it by a question mark. They let a request pass extra information, such as filters, to the endpoint.

Get your free
API
key now
stars rating
4.8 from 1,863 votes
See why the best developers build on Abstract
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
No credit card required