What is REST API in PHP

What is REST API in PHP

Facebooktwitterlinkedin

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

Rest API (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

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 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