What is REST API in PHP

What is REST API in PHP

Facebooktwitterlinkedin

api

What is REST API in PHP and why we need rest api for Android app development?

api REST (Representational State Transfer) api’s are web standards base architecture and uses HTTP Protocol for exchanging data between applications or systems.

In RESTFUL web service HTTP methods like GET, POST, PUT and DELETE can be used to perform CRUD operations.  REST is very simple compare to other methods like SOAP, CORBA, WSDL etc.

What is REST API in PHP

What is REST API in PHP

HTTP methods supported by REST are:

GET It requests a resource at the request URL. It should not contain a request body as it will discard. May be it can  cach locally or on the server.
POST It submits information to the service for processing; it shall typically return the modify or new resource
PUT To update existing resource
DELETE To delete a resource
OPTIONS It indicates which techniques are supported
HEAD About the request URL it returns meta information

HTTP Status Code supported by REST are:

200- OK
201- Created
304- Not Modified
400- Bad Request
401- Unauthorized
403- Forbidden
404- Not Found
422- Unprocessable Entity
500- Internal Server Error

If you are going to build an android Mobile application (it can be any other mobile platform or web too) that manages all the user data on a central database, REST API will be good architectural option to do the communication between the app and the server.

Response Formats:

We can get response in XML or in JSON but JSON is a light weight serialization language that is compatible with many different languages. JSON data parsing is very easy so most of app developer prefer this format.

Success response return by API in JSON:

{  “data”: {    “code”: 200,    “id”: 76,    “name”: “Surjit Singh”  }}

Error response return by API in JSON:

{  “error”: {    “code”: 404,    “message”: “Record not found”  }}

Thank you for reading this article in next article we’ll explain you, How to develop REST API’s using PHP?

Facebooktwitterlinkedin
About the Author