Projects
APIs

APIs

An API (Application Programming Interface) is a solution approach used by applications to access services provided by other applications. APIs are commonly developed in a format known as REST APIs.

  • We will be using a REST API provided by the AWS Rekognition service to pass to it the vehicle license plate image data captured by the camera on the microcontroller.

  • We will also be using REST APIs, developed and deployed for this solution, for the web application to write and read data to and from the NoSQL DB and the Smart Contract.

REST APIs have two components:

  • The endpoint, which is like a regular HTTPS URL via which the client application can call and pass data. Endpoints are deployed on a solution known as an API Gateway.

  • The function which will receive and process the data sent by the client application and send back a response to the client (also referred to as a microservice). While one microservice may receive the initial data sent by the client, it may invoke other internal microservices to perform some of the processing.

In this solution we will use the AWS API Gateway to deploy the required endpoints to be invoked by the microcontroller, which will invoke AWS Lambda functions for processing the data as required. While the approach and code is largely reusable, you will have to adapt to your platform or tech stack if you choose a try a different one.

The diagrams below illustrates how APIs and Lambda functions work together:

API and Lambda Integration

The REST APIs along with their corresponding microservices will perform various functions, including filtering out invalid data, writing and reading data to and from the NoSQL database, sending data to and getting data from the Smart Contract, and using AI/ML services such as AWS Rekognition to process images. Microservices will be implemented as AWS Lambda functions.

This section explains the steps to create REST APIs on AWS and details of the REST API endpoints used in this project and the microservices they will invoke including the inputs they expect, a description of their processing tasks, and the output they provide.

The endpoints will use the domain provided by AWS and not a custom domain. The endpoints for the functions listed below will only provide the custom part which will include the resource name. This will have to be pre-fixed with the domain name part of the URL provided by AWS.

Cross-Origin Resource Sharing (CORS) is a security setting that prevents or allows client web applications running in one domain to interact with resources in a different domain. Since our APIs will be called from the web app which is running in a different domain, you will need to enable CORS.

While we are introducing APIs first since they are the point of access for any component wanting to use the microservices connected with the API, the process requires the microservice (Lambda function) to be created first. We suggest that at this point you move to understanding Lambda functions and creating them and then coming back here to set up the APIs.

APIs

We will be creating only one API for this solution.

  • API for AWS Rekognition Service

This API will be called by the microcontrollers at the loading and unloading locations to send the vehicle number plate image from the camera for recognition and conversion of the vehicle license plate image to registration number as a text value to send to the Smart Contract.

The associated Lambda function will be the receiveAndProcessANPRImage function.

The binary image will be sent in the body of the image. The API will have to be configured to accept all Binary Media Type (/).

This function will call the AWS Rekognition service and will need the IAM permissions to be set accordingly.

The steps to set up the API Gateway and create the API will be shared with subscribers.

In a later version we will create more APIs that can be used by the Web App instead of direct connections using JavaScript libraries as implemented in the current version.