GithubHelp home page GithubHelp logo

dustfoundation / serverless-kit Goto Github PK

View Code? Open in Web Editor NEW
2.0 3.0 0.0 742 KB

Serverless Kit for fast development

License: MIT License

JavaScript 0.60% TypeScript 99.40%
aws serverless aws-serverless

serverless-kit's Introduction

@dustfoundation/serverless-kit

CI NPM Version Minimum Node.js Version

Serverless Kit for fast development.

Installation

npm install --save @dustfoundation/serverless-kit

Features

Authorizer Groups Validation

// User must have at least one of specified groups (moderator OR admin)
hasAnyGroup(event.requestContext.authorizer!.groups.split(';'), ['moderator', 'admin']);
// => boolean
// User must have all specified groups (moderator AND admin)
hasAllGroups(event.requestContext.authorizer!.groups.split(';'), ['moderator', 'admin']);
// => boolean

Parse Request Body (JSON)

const body = parseRequestBody<{ name: 'Elon' }>(event.body, event.headers); // Check Content-Type=application/json
const body = parseRequestBody<{ name: 'Elon' }>(event.body, false); // Skip Content-Type=application/json
if (!body) {
  return BadRequest();
}
// => { name: 'Elon' } | null

Pretty Responses

// Success response
return Success(); // 200

// Success response with body (authomatic JSON.stringify())
return Success().withBody({ name: 'Elon' });

// Success response with body and headers
return Success().withBody({ name: 'Elon' }).withHeaders({ 'test-header': 1 });
return Success().withBody({ name: 'Elon' }).withMultiValueHeaders({ 'test-header': [1] });

// Success response with base64Encoded enabled (for files)
return Success().withBase64Encoded();

// Other responses (withBody and other props can also be applied)
return Created(); // 201
return Accepted(); // 202
return NoContent(); // 204
return BadRequest(); // 400
return Unauthorized(); // 401
return Forbidden(); // 403
return NotFound(); // 404
return Conflict(); // 409
return TooManyRequests(); // 429
return InternalServerError(); // 500
return BadGateway(); // 502
return GatewayTimeout(); // 504

// Custom status codes
return ResponseBuilder(000).withBody(...); // 000

serverless-kit's People

Contributors

hibanka avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.