An API Builder API to detect the labels in a Base64 encoded image using AWS Rekognition
983
An Image Processing API example based on API Builder. Project can be found here on Github. The API leverages AWS Rekognition.
The API is an example of an API First API designed in Stoplight and Built in API Builder as described in the following blog post:
The API is shown below:
POST /detectlabels
with the following body:
{
"image": <Base64 encoded image>
}
which results in the following sample response:
{
"Labels": [
{
"Name": "Car",
"Confidence": 98.41893005371094,
"Instances": [
{
"BoundingBox": {
"Width": 0.9095886945724487,
"Height": 0.4260041415691376,
"Left": 0.044332683086395264,
"Top": 0.37117668986320496
},
"Confidence": 98.41893005371094
}
],
"Parents": [
{
"Name": "Vehicle"
},
{
"Name": "Transportation"
}
]
},
{
"Name": "Automobile",
"Confidence": 98.41893005371094,
"Instances": [],
"Parents": [
{
"Name": "Vehicle"
},
{
"Name": "Transportation"
}
]
},
.
.
.
{
"Name": "Jaguar Car",
"Confidence": 57.534969329833984,
"Instances": [],
"Parents": [
{
"Name": "Car"
},
{
"Name": "Vehicle"
},
{
"Name": "Transportation"
}
]
}
],
"LabelModelVersion": "2.0"
}
For the example above, I use this Base64 encoded data for the car image shown below:

The API uses API Key authentication that is passed in a header with key apikey.
The container requires three env vars:
You can read about AWS credentials here.
You can run the container locally using the following commands:
docker run --name apib_detectlabels -e API_KEY=<AN API KEY THAT YOU CAN CREATE> -e AWS_ACCESS_KEY_ID=<YOUR AWS ACCESS KEY> -e AWS_SECRET_ACCESS_KEY=<YOUR AWS SECRET> -p 8080:8080 --rm lbrenman/apib_detectlabels
curl --location --request POST 'http://localhost:8080/api/detectlabels' --header 'accept: application/json' --header 'apikey: <THE API KEY THAT YOU PROVIDED>' --header 'Content-Type: application/json' --data-raw '{"image":"<YOUR BASE64 ENCODED IMAGE>"}'
Response as shown above.
Content type
Image
Digest
Size
79.3 MB
Last updated
over 4 years ago
docker pull lbrenman/apib_detectlabels