Updated on 2022-10-29 GMT+08:00

Making an API Request

Make a RESTful API request and call the API.

Request URI

A request URI is in the following format:

{URI-scheme} :// {endpoint} / {resource-path} ? {query-string}

Although a request URI is included in the request header, most programming languages and frameworks require the request URI to be transmitted separately.

Table 1 URI parameter description

Parameter

Description

URI-scheme

Protocol used to transmit requests. All APIs use HTTPS.

endpoint

Domain name or IP address of the server bearing the REST service endpoint. The endpoint varies depending on services in different regions. For more details, see Endpoints.

resource-path

Path in which the requested resource is located, that is, the API access path.

query-string

Query parameter, which is optional. Ensure that a question mark (?) is included before each query parameter that is in the format of Parameter name=Parameter value. For example, limit=10 indicates that up to 10 data records will be displayed.

# UAE ID Card OCR
https://ocr.ae-ad-1.g42cloud.com/v2/{project_id}/ocr/emirates-id-card

To simplify the URI display in this document, each API is provided only with a resource-path and a request method. The URI-scheme of all APIs is HTTPS, and the endpoints of all APIs in the same region are identical.

Request Methods

The HTTP protocol defines the following request methods that can be used to send a request to the server:

Table 2 HTTP-defined request methods

Method

Description

GET

Requests the server to return specified resources.

PUT

Requests the server to update specified resources.

POST

Requests the server to add resources or perform special operations.

DELETE

Requests the server to delete specified resources, for example, an object.

HEAD

Same as GET except that the server must return only the response header.

PATCH

Requests the server to update partial content of a specified resource.

If the resource does not exist, a new resource will be created.

# UAE ID Card OCR
POST https://ocr.ae-ad-1.g42cloud.com/v2/{project_id}/ocr/emirates-id-card

Request Header

You can also add additional header fields to a request, such as the fields required by a specified URI or HTTP method. For example, to request for the authentication information, add Content-Type, which specifies the request body type.

  • Content-Type: request body type or format. This field is mandatory and its default value is application/json. Other values of this field will be provided for specific APIs if any.
  • X-Auth-Token: user token. This field is required only for token-based API authentication. For details, see Authentication.

The following provides an example request with a request header included.

# UAE ID Card OCR
POST https://ocr.ae-ad-1.g42cloud.com/v2/{project_id}/ocr/emirates-id-card
Content-Type: application/json
x-auth-token: MIIaBgYJKoZIhvcNAQcC...

Request Body

The body of a request is often sent in a structured format as specified in the Content-Type header field. The request body transfers all content except the request header.

The request body varies depending on APIs. Some APIs do not require the request body, for example, the APIs requested using the GET and DELETE methods.

The request parameters and parameter description can be obtained from the API request. The following provides an example request with a body included.

# UAE ID Card OCR
POST https://ocr.ae-ad-1.g42cloud.com/v2/{project_id}/ocr/emirates-id-card
Request Header:   
Content-Type: application/json   
X-Auth-Token: MIINRwYJKoZIhvcNAQcCoIINODCCDTQCAQExDTALBglghkgBZQMEAgEwgguVBgkqhkiG...       
Request Body:
{
     "image":"/9j/4AAQSkZJRgABAgEASABIAAD/4RFZRXhpZgAATU0AKgAAAAgABwESAAMAA..."
}

If all data required for the API request is available, you can send the request to call the API through curl, Postman, or coding.