close

The REST APIs and OData in SharePoint 2013

Posted by Errin O'Connor on May, 12, 2015 09:05

REST APIs in SharePoint 2013 are now compatible with OData, the industry standard for creating and consuming data APIs. The official reference for OData, as well as to track updates regarding this industry standard, can be found at the following link: http://www.odata.org

OData’s official description, in essence, states that OData builds on core protocols like HTTP and commonly accepted methodologies like REST, resulting in a uniform way to expose full-featured data APIs.

In terms of SharePoint 2013, OData is a protocol for interacting with RESTful web services. It was released under Microsoft’s open specification promise; it works on top of standard HTTP using HTTP GET, POST, PUT, and DELETE verbs and returns standard ATOM or JSON formatted results.

For more information regarding Microsoft’s open specifications promise, refer to the following link:

https://docs.microsoft.com/en-us/openspecs/dev_center/ms-devcentlp/51a0d3ff-9f77-464c-b83f-2de08ed28134

RESTful web services are basically those services or applications that conform to REST constraints, and any service that does not conform to the required constraints should not be considered RESTful.

There is a very strong focus on resources within RESTful web services and they should be simple for a developer to utilize. These services should follow these four principles:

  • Utilize HTTP methods appropriately
  • Expose data in a directory structure
  • Be stateless
  • Transfer either XML or JSON formatted results, as shown in the images below

Microsoft has also recently released a 300-plus page OData/open specifications whitepaper for protocols, file formats, languages, and standards, as well as overviews of the interaction among each of these technologies, which can be accessed at the following link:

https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-odata/2b686a1a-9e1f-456f-80ff-072a010fc278

REST and Search in SharePoint 2013

The new Search capabilities in SharePoint 2013 include a Search REST service that you can utilize to add search features and functionality to your organization’s client applications as well as your mobile applications that support REST web requests.

This capability enables you to use the Search REST service to submit Keyword Query Language (KQL) or FAST Query Language (FQL) queries in apps for SharePoint, mobile apps, and remote client apps. In addition, the new Search REST service also supports both HTTP POST and HTTP GET requests.

For GET requests, you would construct the URI for query GET requests to utilize the Search REST service by using the following:

/_api/search/query

The GET request specifies the query parameters in the URL and can utilize two options for constructing GET requests as detailed here:

http://server/_api/search/query?query_parameter=value&query_parameter=value

or

http://server/_api/search/query(query_parameter=value&query_parameter=<value>)

For POST requests, you would construct the URI for query POST requests to utilize the

Search REST service by using the following:

/_api/search/postquery

The POST requests are passed via the query parameters in the request in JSON format, and the HTTP POST version of the Search REST service supports all the parameters supported by the HTTP GET version.

You should utilize POST requests whenever the following is true:

  • You have concerns about the length of your URL due to URL length restrictions that may be experienced with a GET request.
  • You cannot specify the query parameters via a simple URL such as those in pass parameter values that contain a complex type array because there is added flexibility around the construction of POST requests.

You must ensure that whenever a call is made to the Search REST service, the specific query parameters are included with the request because these query parameters are used to construct the underlying SharePoint search query.

These query parameters are specified in different manners between GET and POST requests:

  • GET requests specify the query parameters in the URL.
  • POST requests pass the query parameters in the body in JavaScript JSON format.

EPC Group’s Nationally Recognized Practice Areas

EPC Group leading Custom Application DevelopmentSharePointOffice 365, Infrastructure Design and Business Intelligence Practice areas continue to lead the way in providing our clients with the most up-to-date and relevant information that is tailored to their individual business and functional needs.

Additional “From the Consulting Trenches” strategies and methodologies are covered in EPC Group’s new book, “SharePoint 2013 Field Guide: Advice from the Consulting Trenches” covering not only SharePoint 2013, Office 365 and SharePoint Online but Information Management, ECM\RM and overall compliance strategies in this ever changing world of “Hybrid IT.”

[gravityforms id=41 title=”true” description=”false”]
<div class='gf_browser_chrome gform_wrapper exit_intent_popup_wrapper gform_legacy_markup_wrapper' id='gform_wrapper_41' > <div class='gform_heading'> <h3 class="gform_title">Exit Intent</h3> <span class='gform_description'></span> </div><form method='post' enctype='multipart/form-data' id='gform_41' class='exit_intent_popup gform_legacy_markup' action='/rest-apis-and-odata-in-sharepoint-2013/' > <div class='gform_body gform-body'><ul id='gform_fields_41' class='gform_fields top_label form_sublabel_below description_below'><li id="field_41_1" class="gfield gform_hidden field_sublabel_below field_description_below gfield_visibility_visible" ><div class='ginput_container ginput_container_text'><input name='input_1' id='input_41_1' type='hidden' class='gform_hidden' aria-invalid="false" value='https://www.epcgroup.net/rest-apis-and-odata-in-sharepoint-2013/' /></div></li><li id="field_41_11" class="gfield gfield--width-full gform_hidden field_sublabel_below field_description_below gfield_visibility_visible" ><div class='ginput_container ginput_container_text'><input name='input_11' id='input_41_11' type='hidden' class='gform_hidden' aria-invalid="false" value='ddd01b75-d4fc-ea11-a816-000d3a591fb8' /></div></li><li id="field_41_12" class="gfield gfield--width-full gform_hidden field_sublabel_below field_description_below gfield_visibility_visible" ><div class='ginput_container ginput_container_text'><input name='input_12' id='input_41_12' type='hidden' class='gform_hidden' aria-invalid="false" value='' /></div></li><li id="field_41_13" class="gfield gfield--width-full gform_hidden field_sublabel_below field_description_below gfield_visibility_visible" ><div class='ginput_container ginput_container_text'><input name='input_13' id='input_41_13' type='hidden' class='gform_hidden' aria-invalid="false" value='' /></div></li><li id="field_41_9" class="gfield gfield_contains_required field_sublabel_below field_description_below gfield_visibility_visible" ><label class='gfield_label' for='input_41_9' >Full Name<span class="gfield_required"><span class="gfield_required gfield_required_asterisk">*</span></span></label><div class='ginput_container ginput_container_text'><input name='input_9' id='input_41_9' type='text' value='' class='medium' placeholder='Full Name' aria-required="true" aria-invalid="false" /> </div></li><li id="field_41_6" class="gfield gfield_contains_required field_sublabel_below field_description_below gfield_visibility_visible" ><label class='gfield_label' for='input_41_6' >Email<span class="gfield_required"><span class="gfield_required gfield_required_asterisk">*</span></span></label><div class='ginput_container ginput_container_email'> <input name='input_6' id='input_41_6' type='text' value='' class='medium' placeholder='Email Address' aria-required="true" aria-invalid="false" /> </div></li><li id="field_41_7" class="gfield gfield_contains_required field_sublabel_below field_description_below gfield_visibility_visible" ><label class='gfield_label' for='input_41_7' >Phone<span class="gfield_required"><span class="gfield_required gfield_required_asterisk">*</span></span></label><div class='ginput_container ginput_container_phone'><input name='input_7' id='input_41_7' type='text' value='' class='medium' placeholder='Phone Number' aria-required="true" aria-invalid="false" /></div></li><li id="field_41_10" class="gfield gfield_contains_required field_sublabel_below field_description_below gfield_visibility_visible" ><label class='gfield_label' for='input_41_10' >Company Name<span class="gfield_required"><span class="gfield_required gfield_required_asterisk">*</span></span></label><div class='ginput_container ginput_container_text'><input name='input_10' id='input_41_10' type='text' value='' class='medium' placeholder='Company Name' aria-required="true" aria-invalid="false" /> </div></li><li id="field_41_8" class="gfield gfield_contains_required field_sublabel_below field_description_below gfield_visibility_visible" ><label class='gfield_label' for='input_41_8' >Message<span class="gfield_required"><span class="gfield_required gfield_required_asterisk">*</span></span></label><div class='ginput_container ginput_container_textarea'><textarea name='input_8' id='input_41_8' class='textarea medium' placeholder='Type your message here...' aria-required="true" aria-invalid="false" rows='10' cols='50'></textarea></div></li></ul></div> <div class='gform_footer top_label'> <input type='submit' id='gform_submit_button_41' class='gform_button button' value='Submit' onclick='if(window["gf_submitting_41"]){return false;} window["gf_submitting_41"]=true; ' onkeypress='if( event.keyCode == 13 ){ if(window["gf_submitting_41"]){return false;} window["gf_submitting_41"]=true; jQuery("#gform_41").trigger("submit",[true]); }' /> <input type='hidden' class='gform_hidden' name='is_submit_41' value='1' /> <input type='hidden' class='gform_hidden' name='gform_submit' value='41' /> <input type='hidden' class='gform_hidden' name='gform_unique_id' value='' /> <input type='hidden' class='gform_hidden' name='state_41' value='WyJbXSIsIjEwNTJhNGVmMWMyNzI3YTJmMjdiZTA1NjU4ZDMzYzY3Il0=' /> <input type='hidden' class='gform_hidden' name='gform_target_page_number_41' id='gform_target_page_number_41' value='0' /> <input type='hidden' class='gform_hidden' name='gform_source_page_number_41' id='gform_source_page_number_41' value='1' /> <input type='hidden' name='gform_field_values' value='' /> </div> <p style="display: none !important;"><label>&#916;<textarea name="ak_hp_textarea" cols="45" rows="8" maxlength="100"></textarea></label><input type="hidden" id="ak_js" name="ak_js" value="49"/><script>document.getElementById( "ak_js" ).setAttribute( "value", ( new Date() ).getTime() );</script></p></form> </div>