API

Explaining APIs with an Example

An API is a set of programming code that enables data transmission between one software product and another. When people speak of “an API”, they sometimes generalize and actually mean “a publicly available web-based API that returns data, likely in JSON or XML”. An API is not the database or even the server; it is the code that governs the access point(s) for the server.

Source: Medium

Types of APIs

Private APIs: These application software interfaces are designed for improving solutions and services within an organization. In-house developers or contractors may use these APIs to integrate a company’s IT systems or applications, build new systems, or build customer-facing apps leveraging existing systems. Even if apps are publicly available, the interface itself remains available only for those working directly with the API publisher. This private strategy allows a company to fully control the API usage.

Partner APIs: Partner APIs are openly promoted, but shared with business partners who have signed an agreement with the publisher. The common use case for partner APIs is software integration between two parties. A company grants partners access to data or capability benefits from extra revenue streams. At the same time, it can monitor how the exposed digital assets are used, ensure that third-party solutions using their APIs provide a decent user experience, and maintain a corporate identity in their apps.

Public APIs: Also known as developer-facing or external, these APIs are available for any third-party developers. A public API program allows for increasing brand awareness and receiving an additional source of income when properly executed.

APIs by Use Cases

APIs can be classified according to the systems for which they are designed.

Database APIs: Database APIs enable communication between an application and a database management system. Developers work with databases by writing queries to access data, change tables, etc. The Drupal 7 Database API, for example, allows users to write unified queries for different databases, both proprietary and open source (Oracle, MongoDB, PostgreSQL, MySQL, CouchDB, and MSSQL).

Operating systems APIs: This group of APIs defines how applications use the resources and services of operating systems. Every OS has its set of APIs, for instance, Windows API or Linux API (kernel–user space API and kernel internal API).

Remote APIs: Remote APIs define standards of interaction for applications running on different machines. In other words, one software product accesses resources located outside the device that requests them, which explains the name. Since two remotely located applications are connected over a communications network, particularly the internet, most remote APIs are written based on web standards. Java Database Connectivity API and Java Remote Method Invocation API are two examples of remote application programming interfaces.

Web APIs: This API class is the most common. Web APIs provide machine-readable data and functionality transfer between web-based systems which represent client-server architecture. These APIs mainly deliver requests from web applications and responses from servers using Hypertext Transfer Protocol (HTTP).

This is the API type that we will be looking at today. An easy way to send web API requests is by using Postman. We will be querying NeoWs (Near Earth Object Web Service) from NASA. This is an open API and no authorization is needed to access it. First, let’s look at different HTTP methods.

HTTP Methods

GET: GET is used to request data from a specified resource.

POST: POST is used to send data to a server to create/update a resource.

PUT: PUT is used to send data to a server to create/update a resource.

HEAD: HEAD is almost identical to GET, but without the response body.

DELETE: The DELETE method deletes the specified resource.

PATCH: Unlike PUT, PATCH applies a partial update to the resource.

OPTIONS: The OPTIONS method describes the communication options for the target resource.

The two most common HTTP methods are: GET and POST.

Example

After installing Postman, you can add a collection from the ‘Create Collection’ button as seen here or by pressing the + next to Collections.

The next step is adding a request, which can be done by pressing the ‘meatballs’ menu. You can name this request whatever you prefer. We will call it NEO.

Now, we paste the URL for the API in ‘Enter request URL’. Make sure that your request type is a GET request.

“https://api.nasa.gov/neo/rest/v1/feed?start_date=2021-05-20&end_date=2021-05-20&api_key=DEMO_KEY”

The ‘Params’ tab is filled in automatically due to the query in the URL. API Query parameters can be defined as the optional key-value pairs that appear after the question mark in the URL. Basically, they are extensions of the URL that are utilized to help determine specific content or action based on the data being delivered. Query parameters are appended to the end of the URL, using a ‘?’. The question mark sign is used to separate path and query parameters. The start_date and end_date can now be specified for a period you want to look at. We are looking at NEOs on 2021-05-20.

This is what the output will look like. Usually, these outputs are in JSON format, working with key-value pairs.

APIs Have Many Advantages:

  1. Automation: With APIs, computers rather than people can manage the work. Through APIs, agencies can update work flows to make them quicker and more productive.
  2. Application: Because APIs can access the app components, the delivery of services and information is more flexible.
  3. More scope: With an API, an application layer can be created which can be used to distribute information and services to new audiences which can be personalized to create custom user experiences.
  4. New data available: An API allows all of the information generated at the government level to be available to every citizen, not just a select few.
  5. Efficiency: when access is provided to an API, the content generated can be published automatically and is available for every channel. It allows it to be shared and distributed more easily.
  6. Integration: APIs allow content to be embedded from any site or application more easily. This guarantees more fluid information delivery and an integrated user experience.
  7. Personalization: Through APIs, any user or company can customize the content and services that they use the most.
  8. Adaptation: Needs change over time and APIs help to anticipate changes. When working with this technology, data migration is supported better, and the information is reviewed more closely. In short, APIs make service provision more flexible.

Source: GitHub

Enjoyed this read?

Stay up to date with the latest AI news, strategies, and insights sent straight to your inbox!

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
LET’S TRY!

Don’t wait get started now!

Build a custom website without the stress, easily customised to suit you.