This article explains the concept of an application programming interface (API) and introduces how they can be used on Peak. 

What is an API?

An API is a piece of software that enables computer systems to communicate with each other.

The APIs on Peak are typically web APIs. These enable computers to communicate over the internet.

APIs, in the more general sense, also allow communication between software libraries, operating systems and hardware.

Why use APIs?

APIs expose only necessary information or functionality to end users.

APIs on Peak are typically used to send payloads of data between Peak and your internal software — for example, by sending the output of a model when a request is made. More complex APIs can be built to perform real-time prediction or automation.

Web APIs are a key component of operationalizing models and getting them into the hands of business users. Web APIs on Peak use the ‘RESTful API framework’, which allows end users to access endpoints via HTTP requests.

What is an endpoint?

An endpoint is a specific server address, typically a uniform resource locator (URL), which provides access to a particular resource such as a function. An API may contain multiple endpoints. Typically these endpoints will expose different functions.

Endpoints can support multiple HTTP methods, for example, a GET method to retrieve the day’s optimization results, or a POST method to provide a payload containing data for a model.

Types of HTTP methods

These are the four most common types of HTTP methods used within endpoints:

  • GET
    Used to request data from a specified resource.

  • POST
    Used to send data to a server to create or update a resource.
    The data sent to the server with POST is stored in the request body of the HTTP request.
    This method is most commonly used to access model prediction functions.

  • PUT
    Used to send data to a server to create or update a resource.
    PUT requests have the additional quality of indempotency, meaning that multiple identical requests have the same outcome.

    Deletes a specified resource.

Before you start, you may want to familiarize yourself with HTTP methods requests; they’re a fundamental component of a web API’s part of the infrastructure.

How to build APIs on Peak

To deploy an API on Peak:

  1. Define what the API does:
    This is contained by API code (for example Flask API or Fast API).

  2. Define how to containerize the API:
    This is contained by a Dockerfile.

  3. Deploy the API: 
    You can then able to deploy the API by creating configurations and endpoints.