Skip to content

apicize/apicize-api-samples

Repository files navigation

Apicize API Samples

This project consists of a couple of APIs that help demonstrate the functionality in [Apicize][https://github.com/apicize/apicize]. They are implemented using AWS Lambda and API Gateway and are deployed using the AWS Serverless Application Model

Functional Overview

https://sample-api.apicize.com/image/(right|flip|left) (POST)

Accepts an image file posted as Base64 and rotates it. Image size is limited by Lambda's invocation payload of 6 MB. Requires bearer token issued by /token.

https://sample-api.apicize.com/quote[/:id] (GET, POST, PUT, DELETE)

CRUD services to store quote information in a DynamoDb database. Requires bearer token issued by /token, and entries are tied to the token used to submit them.

https://sample-api.apicize.com/token (POST)

A minimial OAuth2-ish that issues tokens which expire in 10 minutes. (note: this is not a "real" authentication/authorization service)

Configuration and Deployment

If you are going to deploy this for yourself, refer to the SAM template for parameters to configure.

To run locally, you can create an env.local.json with the following contents (see .env.example.json)

{
    "IssueTokenFunction": {
        "TABLE_NAME_TOKENS": "my-token-table",
        "CIPHER_KEY": "xxxxxxxxxxxx"
    },
    "ImageFunction": {
        "TABLE_NAME_TOKENS": "my-token-table",
        "CIPHER_KEY": "xxxxxxxxxxxx"
    },
    "QuotesFunction": {
        "TABLE_NAME_TOKENS": "my-token-table",
        "TABLE_NAME_QUOTES": "my-quote-table",
        "CIPHER_KEY": "xxxxxxxxxxxx"
    }
}

Running npm start or npm run debug will start the SAM setup locally, including a local instance of DynamoDb.

You can generate a cipher key using the following NodeJS code:

    Buffer.from(await crypto.subtle.exportKey('raw', await crypto.subtle.generateKey({name: 'AES-CBC', length: 256},true,['encrypt','decrypt']))).toString('base64')

Yarn scripts are included to assist with running locally and deploying:

  • build: builds all Lambda functions using esbuild
  • deploy: deploys services to Lambda (you will probaby want to run sam deploy --guided the firsd time to generate a samconfig.toml file)
  • start: launches services locally using AWS SAM
  • debug: launches services locally using AWS SAM with debug enabled

About

Samples demonstrating Apicize functionality

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors