Understanding RESTful APIs, CORS and API basics

Eric Okemwa
3 min readApr 27, 2023

--

Image by gnutec

Regarding software development, APIs play a critical role in enabling different systems to communicate with each other. Understanding APIs is essential for developers working with web-based technologies. In this blog post, we’ll cover the basics of APIs and explore REST, a widely used API design pattern. We’ll also look at CORS and the different HTTP methods used to interact with APIs.

What is an API?

Illustration by Hongkiat

API stands for Application Programming Interface, providing a set of protocols, routines, and tools for building software and applications. APIs enable different software systems to communicate with each other and exchange data. APIs are widely used in modern web-based technologies to provide a consistent and structured way of accessing data.

What is REST?

Illustration by CodeAcademy

REST stands for Representational State Transfer, a widely used API design pattern. REST is a set of architectural principles that define how web-based applications should communicate with each other. RESTful APIs manage resources like GET, POST, PUT, and DELETE. RESTful APIs use URLs to identify resources and use JSON or XML for data representation.

What are other types of APIs?

Illustration by Trio

Different APIs include SOAP, XML-RPC, JSON-RPC, and GraphQL. SOAP is an XML-based protocol for exchanging structured data between different software systems. XML-RPC and JSON-RPC are lightweight protocols used for remote procedure calls. GraphQL is a query language for APIs that enables clients to request only the necessary data.

What is CORS?

Illustraion by Mozilla

CORS stands for Cross-Origin Resource Sharing, a mechanism that enables web-based applications to access resources from different origins. CORS is a security feature built into web browsers that protect users from malicious websites. CORS enables web-based applications to request resources from different origins and enables APIs to share resources with different domains.

HTTP Methods for REST APIs

HTTP methods are used to interact with RESTful APIs. The most common HTTP methods used in RESTful APIs are:

GET — used to retrieve a resource or a collection of resources.

GET /users

POST — used to create a new resource.

POST /users

PUT — used to update an existing resource.

PUT /users/{id}

DELETE — used to delete a resource.

DELETE /users/{id}

How to request REST APIs?

[METHOD] [URL] [HEADERS] [BODY]

To request a RESTful API, you must request an HTTP request to the API endpoint using one of the abovementioned HTTP. For example, to retrieve a list of products from a RESTful API, you can make a GET request to the following URL:

https://api.example.com/products

To create a new product, you can make a POST request to the following URL:

https://api.example.com/products

In conclusion, APIs are a fundamental building block of modern software systems. REST is a widely used API design pattern that enables web-based applications to communicate with each other using HTTP methods. HTTP methods interact with RESTful APIs, and CORS enables web-based applications to access resources from different origins. Understanding the basics of APIs, REST, and CORS is essential for developers working with modern web-based technologies.

Sources

1.github.com/Hhbecker/ConsiderateBlueWhalesubject to license (MIT)

2.tutorialbox.org/what-is-rest-api

3.www.ibm.com/topics/rest-apis

--

--

Eric Okemwa
Eric Okemwa

Written by Eric Okemwa

Let’s connect and make the complex simple!

No responses yet