Monday, March 29, 2021

How API Connectors Work


What is an Application Programming interface? It's exactly what it says - an interface between two application programs, a piece of software that allows different apps to communicate with each other. In the same way that you use the black box pieces of code on a no-code platform to build an app, your app can use an API to create a connection to another application like Stripe or Facebook and exchange information with that service. The API itself is simply a piece of software installed on the server you want to access. 

When the two computers connect or "integrate" via the API, they have to agree on the set of rules (or "protocol") they're going to use to communicate with each other (similar to two people deciding what language to use to carry on a conversation). Since Hyper-Text Transfer Protocol (HTTP) is the most common protocol on the Internet, many APIs use it as their communication protocol.

Once a connection is established, the client (your app) sends a request to the other computer (the server) and receives one of three responses (an acknowledgment that the request was handled successfully, an error message explaining that the request failed, or the data requested by your app). The request sent by your app is made up of four parts:

  • A URL that provides the location you want to connect to on the server. The URL itself consists of three parts:
    • The address of the server (www.youtube.com).
    • The specific location you want to reach on the server (/results).
    • The query string parameters (?search_query=bubble.io).
  • The HTTP method:
    • GET request - Asks the server to retrieve a resource (a webpage, product, image, etc.).
    • PUT request - Asks the server to update a resource (change the address in a customer record for example).
    • POST request - Asks the server to create a new resource (e.g. create a new customer record with the data in the body of the request).
    • DELETE request - Asks the server to remove a resource (e.g. delete an inactive customer record).
  • Header records: Additional information to pass on to the server, such as the time of the request, the request authorization, type of content, and response cookies. 
  • The Body: The body of an API request contains the data that your app wants to send to the server and that data has to follow a specific format that the server can understand. A typical API connector encodes the data in a text-based format called JSON (JavaScript Object Notation). Here's an example of data in JSON format:  { “First name”:”Gary”, "Last name":"Morrison", ”Company”:”Global Imports”, "Email": "GaryM@global.com", “Primary contact”:true}.
Most servers require you to send a unique authorization code (referred to as an "API-Key") that identifies you to the server. The third-party service will issue you an API-key (normally a long string of random-looking characters) when you sign up. There are several ways that an HTTP API-key can be included in your request:
  • As part of a query string in the URL (?something+API-key). 
  • In an HTTP header record.
  • A user name and password (which act as the API-key) can be sent as part of each request.
Once the server receives a request it will try to fulfill it, then it will send a response back to the client. Similar to a request, an HTTP response has three parts: a 3-digit status code, headers, and a body. 

Status codes indicate whether the request was handled successfully or not. Common status codes include:
  • 200 - Request succeeded.
  • 404 - The requested resource doesn't exist.
  • 503 - Website is currently unavailable.
There are actually five classes of response:
  • 1xx - Request received, continuing to process.
  • 2xx - Success (requested data delivered or requested action completed).
  • 3xx - Redirection (additional processing needed to complete the request).
  • 4xx - Client errors; the request isn't correctly structured or can't be fulfilled.
  • 5xx - Server errors; the server failed to handle the request correctly.
Once the response is delivered, that round of the request/response cycle is complete. Any further interaction through the API is up to the client. 

That's the general idea of how an API works - but how do you make use of one on your no-code platform? Most no-code platforms have a way to connect to various APIs, either through some function that's an integral part of the platform, or through a plugin or a third-party integration service. For example, Zoho Creator has an easy-to-follow description of how to use its API service at:https://www.zoho.com/creator/help/api/v2/  

I'll go into a little more detail on the mechanics of API connections in a later post. Meanwhile, I hope you get a chance to experiment with including API calls in your app - API integration has become an important part of application planning, whether for traditional, low-code, or no-code apps.

No comments:

Post a Comment