Skip to content

kaskadi/products-api

Repository files navigation

GitHub Actions workflows status

Deploy status Build status Docs generation status

CodeClimate


API endpoints

The origin and root path for this API is: https://api.klimapartner.net/products

The following endpoints are defined in this API:

/

Supported methods:

GET (target lambda → products-root-handler)

Description:

This endpoint is a fallback for when client forgets to provide an ID for product data retrieval.

Authorization:

Type Identity source
Cognito
  • method.request.header.Authorization

Query string parameters:

No query string parameters found for this method.

Request body:

No body found for this method.

Examples:

Example #1

Request:

GET https://api.klimapartner.net/products/

Headers:
  Authorization: Bearer COGNITO_ACCESS_TOKEN

Response:

Status code:
  400

Headers:
  Access-Control-Allow-Origin: *

Body:
  {
    "message": "Path parameter for product ID missing... (/products/{id})"
  }

POST (target lambda → products-root-handler)

Description:

This endpoint is a fallback for when client forgets to provide an ID for product data update.

Authorization:

Type Identity source
Cognito
  • method.request.header.Authorization

Query string parameters:

No query string parameters found for this method.

Request body:

No body found for this method.

Examples:

Example #1

Request:

POST https://api.klimapartner.net/products/

Headers:
  Authorization: Bearer COGNITO_ACCESS_TOKEN

Response:

Status code:
  400

Headers:
  Access-Control-Allow-Origin: *

Body:
  {
    "message": "Path parameter for product ID missing... (/products/{id})"
  }

DELETE (target lambda → products-root-handler)

Description:

This endpoint is a fallback for when client forgets to provide an ID for product deletion.

Authorization:

Type Identity source
Cognito
  • method.request.header.Authorization

Query string parameters:

No query string parameters found for this method.

Request body:

No body found for this method.

Examples:

Example #1

Request:

DELETE https://api.klimapartner.net/products/

Headers:
  Authorization: Bearer COGNITO_ACCESS_TOKEN

Response:

Status code:
  400

Headers:
  Access-Control-Allow-Origin: *

Body:
  {
    "message": "Path parameter for product ID missing... (/products/{id})"
  }

/search

Supported methods:

GET (target lambda → search-products)

Description:

This endpoint allows client to perform a product search via a query. Results are paginated.

Authorization:

Type Identity source
Cognito
  • method.request.header.Authorization

Query string parameters:

Key Default Description
p Request a specific page of the search results.
s 10 Amount of search results returned per page.
q Query used to perform the product search. This follows ElasticSearch query string syntax.

Request body:

No body found for this method.

Examples:

Example #1

Request:

GET https://api.klimapartner.net/products/search?p=1&s=50&q=*

Headers:
  Authorization: Bearer COGNITO_ACCESS_TOKEN

Response:

Status code:
  200

Headers:
  Access-Control-Allow-Origin: *

Body:
  In here will be an array (Object[]) which reflects the 50th to 100th products found (p=1&s=50) while searching for all products (q=*).
Example #2

Request:

GET https://api.klimapartner.net/products/search?p=1&s=50

Headers:
  Authorization: Bearer COGNITO_ACCESS_TOKEN

Response:

Status code:
  400

Headers:
  Access-Control-Allow-Origin: *

Body:
  {
    "message": "Query string parameter q is missing... Please provide a valid query for your search."
  }

/{id}

Supported methods:

DELETE (target lambda → delete-product)

Description:

This endpoint allows client to delete a specific product via its ID.

Authorization:

Type Identity source
Cognito
  • method.request.header.Authorization

Query string parameters:

No query string parameters found for this method.

Request body:

No body found for this method.

Examples:

Example #1

Request:

DELETE https://api.klimapartner.net/products/valid_id

Headers:
  Authorization: Bearer COGNITO_ACCESS_TOKEN

Response:

Status code:
  200

Headers:
  Access-Control-Allow-Origin: *

Body:
  {
    "message": "Product with ID valid_id successfully deleted!"
  }
Example #2

Request:

DELETE https://api.klimapartner.net/products/non_existant_id

Headers:
  Authorization: Bearer COGNITO_ACCESS_TOKEN

Response:

Status code:
  404

Headers:
  Access-Control-Allow-Origin: *

Body:
  {
    "message": "Product not found..."
  }

GET (target lambda → get-product)

Description:

This endpoint allows client to retrieve data of a specific product via its ID.

Authorization:

Type Identity source
Cognito
  • method.request.header.Authorization

Query string parameters:

No query string parameters found for this method.

Request body:

No body found for this method.

Examples:

Example #1

Request:

GET https://api.klimapartner.net/products/valid_id

Headers:
  Authorization: Bearer COGNITO_ACCESS_TOKEN

Response:

Status code:
  200

Headers:
  Access-Control-Allow-Origin: *

Body:
  {
    "product-data-1": "some product data",
    "product-data-2": "another product data field",
    "product-data-N": "the last field of data for this product"
  }
Example #2

Request:

GET https://api.klimapartner.net/products/non_existant_id

Headers:
  Authorization: Bearer COGNITO_ACCESS_TOKEN

Response:

Status code:
  404

Headers:
  Access-Control-Allow-Origin: *

Body:
  {
    "message": "Product not found..."
  }

POST (target lambda → save-product)

Description:

This endpoint allows client to update data of a specific product via its ID. The request body should contain the new product data.

Authorization:

Type Identity source
Cognito
  • method.request.header.Authorization

Query string parameters:

No query string parameters found for this method.

Request body:

Key Default Description
example-field-1 A data field to write in the database for the given product
example-field-N A data field to write in the database for the given product

Examples:

Example #1

Request:

POST https://api.klimapartner.net/products/product_id

Headers:
  Authorization: Bearer COGNITO_ACCESS_TOKEN

Body:
  {
    "product-data-1": "some product data",
    "product-data-2": "another product data field",
    "product-data-N": "the last field of data for this product"
  }

Response:

Status code:
  200

Headers:
  Access-Control-Allow-Origin: *

Body:
  {
    "message": "Product with ID product_id successfully saved!"
  }
Example #2

Request:

POST https://api.klimapartner.net/products/product_id

Headers:
  Authorization: Bearer COGNITO_ACCESS_TOKEN

Response:

Status code:
  400

Headers:
  Access-Control-Allow-Origin: *

Body:
  {
    "message": "Request body missing: no product data to save..."
  }

API resources

The following lambda functions are used in this API:

The following layers are used in this API:

delete-product

Name Sources Timeout Handler Layers
delete-product
  • HTTP (DELETE)
default handler

See configuration file for more details.

get-product

Name Sources Timeout Handler Layers
get-product
  • HTTP (GET)
default handler

See configuration file for more details.

search-products

Name Sources Timeout Handler Layers
search-products
  • HTTP (GET)
30s handler

See configuration file for more details.

save-product

Name Sources Timeout Handler Layers
save-product
  • HTTP (POST)
default handler

See configuration file for more details.

products-root-handler

Name Sources Timeout Handler Layers
products-root-handler
  • HTTP (GET)
  • HTTP (POST)
  • HTTP (DELETE)
default handler

See configuration file for more details.

products-api-layer

Description

Layer for products-api

Dependencies

  • aws-es-client, version: 1.0.2 (see on NPM)
  • products-api-utils (local utility)

See configuration file for more details.

Stack tags

You can use any tags (and their respective values) visible below to find ressources related to this stack on AWS. See here for more details.

Tag Value
app kaskadi
service products-api
logical-unit products
type http