Showing posts with label REST API. Show all posts
Showing posts with label REST API. Show all posts

Monday, February 18, 2019

Odata and REST APIs - A Comparison



Are you curious about what is REST and OData? Then, this article is for you. In it, you will find an explanation of what is REST, how it is applied to the construction of RESTful APIs; what is OData and how it is used to build web services, and the differences between the two.

Brief comparison

The table below summarizes the main similarities and differences between REST APIs and OData Services.



Table1: REST and OData comparison

As the table shows, both technologies follow REST principles, although OData is more relaxed in that, if there is a good reason to avoid its use, it lets you do so.

Thus the OData Protocol is more comprehensive than the REST model, as in addition to the use of the REST principles, it provides a way to describe both the data and the data model.

So, let’s go deep into the details by explaining each of the concepts mentioned in the above table.

What is REST

Representational State Transfer, or better known as REST is a software architecture style, which defines a set of principles useful for creating efficient web services.

These principles were described by Roy Fielding in his doctoral dissertation written in 2000. As he stated during an interview:

“…That process honed my model down to a core set of principles, properties, and constraints that are now called REST”

In his dissertation Fielding identified six aspects of HTTP and HTML that made these technologies successful and efficient. These concepts or principles are:

  1. Client–server
  2. Stateless
  3. Cacheable
  4. Layered system
  5. Code on demand (optional)
  6. Uniform interface
    • Identification of resources
    • Manipulation of resources through these representations
    • Self-descriptive messages
    • Hypermedia as the engine of application state (HATEOAS)

The HTTP protocol is an example of a system that implements the principles of REST.

What is a REST API

A REST API is simply an Application Programming Interface that uses the above mentioned principles. Usually, they use XML or JSON to communicate, although the REST architecture doesn’t ask anything specific in this regard. Even more, REST doesn’t demand any particular format, and accepts any format that can be used via Content negotiation.



Figure 1: REST API

What is OData

OData or Open Data protocol is an application-level protocol that describes a way for interacting with data using RESTful services. At present it is in version 4.0. This latest version was standardized by OASIS and approved as an ISO/IEC International Standard.

Initially created by Microsoft in 2007, it was later released under the Microsoft Open Specification Promise, and thus made available to all.

The protocol is based on two main components: 
  1. Industry standards: HTTP, XML, Atom and JSON.
  2. REST-based architecture: HTTP protocol.

However, the specification states that:

  1. OData must “follow REST principles unless there is a good and specific reason not to”.
  2. OData Services MUST support the ATOM encoding.
  3. OData services SHOULD support a JSON encoding.

Figure 2 shows the structure of an OData compliant web service. It rests on HTML technology, which somehow resolves the problem of being REST-based. In addition, it must include Atom encoding, which is based on the XML technology, and also adhere to the OData’s data handling specifications. Since version 4.0, OData also handles JSON.



Figure 2: an OData compliant construct

OData uses Atom or JSON to define the data schema, and it provides two important models for the management of data. They are: 
  1. Entity Data Model or EDM: it is an abstract data model that MUST be used to describe the data exposed by the service.
  2. Service Model: it consist of two static resources and a set of dynamic resources. The static resources provide a way to ask a service about its data model, and the dynamic ones offer methods to manage the data model.

The two static resources are: 
  1. The metadata document, which describes the data model.
  2. The service document, which lists all of the top-level entity sets exposed by the service.

An important feature of the OData protocol is its support for a versioning scheme that enables services to be backward compatible.

In addition, there are several libraries that can be used to facilitate building and consuming OData-based services. Among them, Restier is the main library for the .NET framework, and Apache Olingo is the most important for the Java platform.

Conclusion

In this article we have seen what REST means, how it is used in RESTful APIs and in the OData Protocol. In addition, we have described the OData protocol’s main components.

We have concluded that REST is part of OData, and also more general. Thus, OData can be considered a safer guide to creating RESTful services.

Read more related articles at our blog series

Thursday, February 22, 2018

Speed up connectors’ turnaround with swagger specification

What is Swagger
Swagger is the world’s most popular and largest framework of API’s developer tools for the open API specification, enabling development across the entire API lifecycle, from design and documentation to test and deployment.

How Swagger Specifications Have Revolutionized API Ecosystem
In the developer community, with the growing popularity of RESTFUL web services over SOAP there’s a need to have one common standard for designing, developing and documenting APIs. The Swagger specifications come very handy in connecting engineers through their API’s to communicate with each other in a semantic fashion irrespective of the language used to design an API.
Swagger is an framework for describing a common language that everyone can understand. The OpenAPI (Swagger) Specification is a standard, language-agnostic interface to RESTful APIs that allows humans and computers to discover and understand the capabilities of a service without having to access the source code, documentation or through network traffic inspection.
Even though there are few other frameworks like RAML, API Blueprint which have gained some popularity, Swagger is still most popular framework in documenting APIs due to the following factors.

  • Open source. Swagger being the first Open Source API framework is great and it’s simple to get started with the OpenAPI Specification. It’s clean, efficient, armed with number of powerful features and helps you to design and document your RESTful interfaces straight out of the box.
  • Smart feedback. You can validate your Syntax for Swagger Compliance as you write it with concise error feedback and error handling capabilities. You can also render your API specification visually and interact with your API while you are still defining it.

  • Fully customisable. Easy to configure and customize anything, from line-spacing to themes. You can also generate server stubs and client libraries for your API in any popular language.

The above benefits not only make developer’s life easier but also provide users with smoothly consumable APIs. Any API that adheres to the Swagger Specification are easy to read, iterate and readily consumed. Recently the Swagger Specifications has been moved to Linux Foundation under the name the Open API Initiative, as well as backed by IT giants like Microsoft, Google, Intuiti, Atlassian that focus on creating, evolving and promoting a vendor neutral description format.
In the following section of the article I outline one such use-case in building custom connector, JIRA Service Desk.

Use Case
DBSync uses Swagger Specification through its API connector to build JIRA Service Desk connector that has considerably reduced the whole build cycle in releasing a new connector to the market.
The DBSync’s API connector can effectively integrate with any external system such as JIRA Service Desk by implementing the necessary Swagger Specifications and ApiCode interface. API connector is the fastest way to build any application connector which readily exposes its APIs to the public that may or may not adhere to Swagger or any other API specifications.

Integration is done by documenting all the JIRA Service Desk APIs in JSON object adhering to the Swagger Specifications.
Developing Jira Service Desk connector is as simple as creating a new Swagger JSON object that contains all the endpoints along with the parameters and return types that you would like to expose through the connector (this would fetch all the API metadata that will help in establishing the connection). This JSON object is internally consumed by API connector to expose JIRA Service Desk as an individual connector that can be used in Integration life cycle within the iPaaS.

Leveraging DBSync iPaaS for making API calls with JIRA Service Desk
DBSync’s JIRA Service Desk connector uses JIRA Service Desk APIs along with JIRA Core API’s to move data in and out of the application. This integration consists of REST calls using a JSON request/response made over an HTTPS connection. Therefore all of HTTP methods like, get, post, put and delete are supported as a part of the implementation.
Trigger section is used to fetch data from the source application within the platform. Using JIRA Service Desk connector we expose GET endpoints of the APIs that will equip the user to read data in a controlled way.
Rule section within platform is used to define the manner in a way the user want to write data to the target application which can be either a single data source or multiple data sources. In this section of the platform we expose, post, put API endpoints to pass the data to the desired API. The endpoint names alone are not enough to manage the entire integration life cycle in the iPaaS. Additionally the platform should also know the parameters that need to be passed to an API endpoint and return type parameters that are required for field mappings in transformation process.


Likewise, one can leverage the DBSync iPaaS for connecting with JIRA Service Desk and any other application to facilitate the data flow between them. By including API connector to its catalogue, DBSync has made process of building, publishing and deploying new connectors easier, within just a few days by following Swagger Specification. The platform has the ability to connect with legacy application or SaaS based application that have their API exposed.