Wednesday, 20 December 2017

REST Integration

REST : Representational State Transfer

REST is a simple way of sending and receiving data between client and server.
It supports transfer of data by JSON/XML/Plain text

Idempotent :

If you send retry a request multiple times, that should be equivalent to single request modification.
Ex: Whenever you are trying to POST a comment in site,By mistake double clicked the submit it creates two comments in the server.Since POST is not Idempotent it behaves that way.

Safe Methods : 

Do not modify the resource in the server.

Ex: GET

What are the HTTP Methods for RESTful Services ?


HTTP Method
Details
Idempotent
Safe Method
GET
GET request should be used only to fetch some information from the server.
Yes
Yes
POST
POST request can be used to create a new resource or to update an existing resource in the server.
No
No
PUT
PUT If the Request-URI refers to an already existing resource – an update operation will happen, otherwise create operation should happen.

Note: If and only if updating the full content of the specified resource. PUT should be used.

Yes
No
PATCH
PATCH for Partial Update of content
No
No
DELETE
DELETE method should be used to remove or delete something from the server
Yes
No


POST VS PUT

Ideally POST should use for creation of new resource & PUT for updating the existing resource.

Again it's design decision :
1.The end point must be idempotent
2. If request URI contains the existing resource update operation if not create the mentioned resource

If any one is not needed use POST else use PUT

REST Integration Requirement / Salesforce Coding Test Scenario :

Get the GeoCode [Lattitue,Longitude] & formatted_address from GoogleMap API

Implementation :

Apex Class
Description
BLG_RESTAPICall_Ex
GoogleMapAPI call & Parsing the response JSON
BLG_GoogleMapAPIResponse
GoogleMapAPI JSON Response class



Is there any limit on REST request payload ?

HttpPost doesn't have size limit, but usually limited by the server to request is sent to.






1 comment:

  1. Gmail to Salesforce. Extension for Google Chrome that integrates your Gmail inbox with Salesforce. This extension adds a button to your Gmail page that allows to easily attach your received and/or send emails to Salesforce Objects in a couple of clicks.

    Click to : Integrate Gmail to salesfore
    Hire Web developer

    ReplyDelete