Member-only story

Understanding REST API: A Simple Guide

Manish Kumar, Owner @Pixospace
3 min readJan 11, 2024

--

REST API stands for Representational State Transfer Application Programming Interface. It’s a set of rules that allows software to talk to each other via the internet. REST APIs use standard web methods, which are like different types of requests you can make to access or change data on a server.

The Methods of REST API:

REST APIs mainly involve five methods: GET, POST, PUT, DELETE, and PATCH. Let’s explore each with PHP code examples:

  1. GET Method

Use: To get or retrieve data from a server.
Idempotent: Yes (calling it any number of times produces the same result).
Key Point: GET requests don’t change the server’s data.
PHP Example:

// Using cURL to send a GET request
$curl = curl_init('http://example.com/api/users');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($curl);
curl_close($curl);

2. POST Method

Use: To send data to a server to create a new resource.
Idempotent: No (calling it multiple times will create multiple resources).
Key Point: POST requests create new data on the server.
PHP Example:

--

--

Manish Kumar, Owner @Pixospace
Manish Kumar, Owner @Pixospace

Written by Manish Kumar, Owner @Pixospace

12 yrs as a PHP dev, 7 in Laravel. Now a full-time freelancer writing about coding, freelancing, and tech fixes on Medium.

No responses yet