Hi,

It is true that using GET request with a payload is not the best option.
Even though it is not strictly prohibited in specs, it can be confusing
[1]. REST architecture is very open about how we use HTTP methods, but
thinking in terms of REST architecture, I do not think using POST is also
the correct approach here [2] (maybe it is just the personal preference).

Let me summaries few examples on how others have addressed the same
requirement with GET requests.

Facebook Graph API is using "field" query parameter for this [3]. For
example :

Following Graph API call
*https://graph.facebook.com/bgolub?fields=id,name,picture
> <https://graph.facebook.com/bgolub?fields=id,name,picture>* will only
> return the id, name, and picture in Ben's profile
>

SharePoint syntax is not very eye candy [4][5], but it goes like :

http://server/siteurl/_vti_bin/listdata.svc/DocumentsOne?$select=MyDocumentType,Title,Id&$expand=MyDocumentType
>

YouTube API has the same in below form [6] :

Example 1: Retrieve number of items in feed, index of
> first item in result set, and all entries in the feed:
>     fields=openSearch:totalResults,openSearch:startIndex,entry
>

LinkedIn has the same [7]

https://api.linkedin.com/v1/people-search:(people:(id,first-name,last-name,positions:(id,title,summary,start-date,end-date,is-current,company:(id,name,type,size,industry,ticker))
>

IMO Facebook Graph API has the cleanest mechanism.

I believe that if we use a similar format we will not have to introduce new
resource paths. Instead we'll be able to provide all the columns, unless
user specifically request limited set of fields with a query parameter.
WDYT?

[1]
http://stackoverflow.com/questions/5216567/is-this-statement-correct-http-get-method-always-has-no-message-body
[2] https://spring.io/understanding/REST
[3]
https://developers.facebook.com/docs/graph-api/using-graph-api#fieldexpansion
[4]
http://sharepoint.stackexchange.com/questions/118633/how-to-select-and-filter-list-items-lookup-column-with-sharepoint-2013-rest-feat
[5]
http://platinumdogs.me/2013/03/14/sharepoint-adventures-with-the-rest-api-part-1/
[6]
https://developers.google.com/youtube/2.0/developers_guide_protocol_partial#Fields_Formatting_Rules
[7] https://developer.linkedin.com/docs/fields?u=0

Best Regards,
Ayoma.

On Wed, Mar 23, 2016 at 8:13 PM, Lahiru Sandaruwan <[email protected]> wrote:

> Hi,
>
> I think using a POST with a body, for retrieving information is fine
> considering the requirement. GET with body is not recommended.
>
> Thanks.
>
> On Wed, Mar 23, 2016 at 2:31 PM, Gimantha Bandara <[email protected]>
> wrote:
>
>> Hi all,
>>
>>
>> We have a REST API in DAS to retrieve records in a specific table. It
>> supports GET method with the following url format.
>>
>> /analytics/tables/{tableName}/{from}/{to}/{start}/{count}
>>
>> Sending a GET request to above url will give the records between given
>> "from", "to" time range starting from index "start" with  "count"  page
>> size.
>>
>> Now we need to change the API, so that the user can define the record
>> columns/fields he wants. Current API will return the records with all the
>> values/columns. To do that, we can allow the user to define the columns he
>> needs, in the payload. But it seems that having a payload with a GET is not
>> the convention/the best practice.
>>
>> POST can be used to send the column names as a payload, but here we are
>> not making any updates to {tableName} resource. We will be just retrieving
>> records using a POST. So it also seems not the convention/the best practice.
>>
>> The only solution I can think of is, having a different resource path to
>> get the records with only specified fields/columns. Are there any other
>> solutions?
>>
>> Thanks,
>> Gimantha
>>
>>
>> _______________________________________________
>> Architecture mailing list
>> [email protected]
>> https://mail.wso2.org/cgi-bin/mailman/listinfo/architecture
>>
>>
>
>
> --
> --
> Lahiru Sandaruwan
> Committer and PMC member, Apache Stratos,
> Senior Software Engineer,
> WSO2 Inc., http://wso2.com
> lean.enterprise.middleware
>
> phone: +94773325954
> email: [email protected] blog: http://lahiruwrites.blogspot.com/
> linked-in: http://lk.linkedin.com/pub/lahiru-sandaruwan/16/153/146
>
>
> _______________________________________________
> Dev mailing list
> [email protected]
> http://wso2.org/cgi-bin/mailman/listinfo/dev
>
>


-- 
Ayoma Wijethunga
Software Engineer
WSO2, Inc.; http://wso2.com
lean.enterprise.middleware

Mobile : +94 (0) 719428123 <+94+(0)+719428123>
Blog : http://www.ayomaonline.com
LinkedIn: https://www.linkedin.com/in/ayoma
_______________________________________________
Architecture mailing list
[email protected]
https://mail.wso2.org/cgi-bin/mailman/listinfo/architecture

Reply via email to