RESTful API Technology Overview
A lot of different technologies have been integrated over time to create the APIs we know and love today. Read on to get a great overview of these API enablers!
Join the DZone community and get the full member experience.Join For Free
what technology goes into an api?
apis are driven by a set of specific technologies, making them easily understood by a wide variety of developers.
a focus on simplicity means that apis can work with any common programming language and be understood by any programmer, even one with little or no training in api technology.
application programming interface ( api ) is a set of clearly defined methods of communication between various software components. a good api makes it easier to develop a computer program by providing all the building blocks. while the specifications vary between various apis, the end goal is to provide value to the programmer through utilization of the services gained from using an api.
the most popular approach to delivering web apis is representational state transfer ( rest ). this approach to api design takes advantage of the same internet mechanisms (based on the http protocol) used to view regular web pages, so it has the advantage of faster implementations and is easier for developers to understand and put to use.
rest apis allow you to take information and functionality that is already available on your website and then quickly make it available through a programmatic api, so that both web and mobile applications can reuse it, dramatically extending your company's reach over new channels, all without much additional work.
json has become one of the preferred ways for programmers to enable api communication. it provides a lightweight, simple way to exchange data across the internet while maintaining the structure and meaning of that data.
api security is the single biggest challenge organizations want to see solved in the years ahead, and solving the security challenge is expected to be a catalyst for growth in the api world.
according to research by smartbear presented in their state of apis report 2016:
- security is the #1 technology challenge teams want to see solved; 41.2% of respondents say security is the biggest api technology challenge they hope to see solved.
- security is the #4 technology area expected to drive the most api growth in the next two years; 24% of api providers say digital security will drive the most api growth in the next two years.
- 40.4% of api providers are currently utilizing a tool for testing api security.
this is not any kind of formal standard, but something like a common practice by api providers, and supported by api management providers - the usage of one or two keys that accompany every api call. api keys are really more about identifying the application and user rather than a true security protocol, but it is perceived as secure by many.
public rest services without access control run the risk of being farmed, leading to excessive bills for bandwidth or compute cycles. api keys can be used to mitigate this risk. they are also often used by an organization to monetize apis; instead of blocking high-frequency calls, clients are given access in accordance with a purchased access plan.
typically, an api key gives full access to every operation an api can perform, including writing new data or deleting existing data. if you use the same api key in multiple apps, a broken app could destroy your users' data without an easy way to stop just that one app. some apps let users generate new api keys, or even have multiple api keys with the option to revoke one that may have gone into the wrong hands. the ability to change an api key limits the security downsides.
http basic authentication implementation is the simplest technique for enforcing access controls to web resources because it doesn't require cookies, session identifiers, or login pages; rather, http basic authentication uses standard fields in the http header, removing the need for handshakes.
to receive authorization, the client sends the userid and password, separated by a single colon (":") character, within a base64 encoded string in the credentials.
if the user agent wishes to send the userid "aladdin" and password "open sesame," it would use the following header field:
authorization: basic qwxhzgrpbjpvcgvuihnlc2ftzq==
the basic authentication scheme is not a secure method of user authentication, nor does it in any way protect the entity, which is transmitted in cleartext across the physical network used as the carrier.
the most serious flaw in basic authentication is that it results in the essential cleartext transmission of the user's password over the physical network.
because basic authentication involves the cleartext transmission of passwords it should be used over tls or ssl protocols (https) in order to protect sensitive or valuable information.
open authorization (oauth 2)
created in 2006, oauth 2 is an open standard for authentication protocols that provides authorization workflow over http and authorizes devices, servers, applications, and apis with access tokens instead of credentials. oauth gained popularity from usage by facebook, google, microsoft, and twitter, who allow usage of their accounts to be shared with third-party applications or websites.
oauth 2.0 can be used to read data of a user from another application without compromising the user's personal and sensitive data, like user credentials. it also supplies the authorization workflow for web and desktop applications and mobile devices.
the previous versions of this spec, oauth 1.0 and 1.0a, were much more complicated than oauth 2.0. the biggest change in the latest version is that it's no longer required to sign each call with a keyed hash. the most common implementations of oauth use one or both of these tokens instead:
- access token : sent like an api key, it allows the application to access a user's data; optionally, access tokens can expire.
- refresh token : optionally part of an oauth flow, refresh tokens retrieve a new access token if they have expired.
since an access token is a special type of api key, the most likely place to put it is the authorization header, like so:
authorization: bearer 1234567890abcdef
json web token (jwt)
json web token ( jwt ) is an open standard, an extension of the oauth 2.0, for creating access tokens that assert some number of claims.
whereas api keys and oauth tokens are always used to access apis, json web tokens (jwt) can be used in many different scenarios. in fact, jwt can store any type of data, which is where it excels in combination with oauth.
like oauth access tokens, jwt tokens should be passed in the authorization header:
authorization: bearer eyjhbgcioijiuzi1niisinr5cci6ikpxvcj9.eyjob21lcgfnzsi6imh0dhbzoi8vemfwawvylmnvbsisinrhz2xpbmuioijayxbpzxigbwfrzxmgew91ighhchbpzxiilcjmb3jtijoiahr0chm6ly96yxbpzxiudhlwzwzvcm0uy29tl3rvl0hkrvk0eij9.e3etyy2y7brn4es0riydaah-kasa6dvv91ulbbjcrjw
webhooks are a form of push notifications that can be triggered by a specific action. when triggered, they push information to an external website address. webhooks allow developers to choose the action, url, and fields associated with the webhook push. once a webhook is triggered, it passes all associated information to the location where a developer can process it.
webhooks became very popular, and, even in openapi 3 , you can define the format of the "subscription" operation as well as the format of callback messages and expected responses to these messages. this description will simplify communication between different servers and will help you standardize the use of webhooks in your api. today, many tools help you create webhooks based on the openapi spec and even helps you build your api definitions wysiwyg .
webhooks are a great way to reduce constant polling on an api because they push data to api developers only when the required action is triggered. webhooks make the api a two-way street, allowing developers to not only pull data from api platforms but also receive data in real time as events occur.
rest, json, oauth, jwt, and webhooks have become the preferred technology for both api providers and api consumers, because they stick with the core principles of simplicity, security, making data and resources accessible, and easily integrating into web and mobile applications.
this suite of web api technologies was not designated by a single standards body or by a single company. it has been established over the past 13 years through the best practices of existing, successful api providers that are meeting the demands of developers.
Published at DZone with permission of Guy Levin, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.