generate-serverless-endpoints

1.1.0 • Public • Published

Generate Serverless Endpoints

Generate boilerplate definitions for serverless API endpoints by answering questions.

Usage

At the command line:

$ npx generate-serverless-endpoints

Example prompts:

jeff@amazon:~/my-lambda$ generate-endpoints 

Use {named} variables in the path to declare path parameters.

? What is the new endpoint's path? /users/{id}/settings
? Which methods are supported? GET, PUT
? Is the endpoint private (requires API key)? Yes

Example output:

Copy and paste this into your serverless.yml file:

functions:
  getUsersNotifications:
    handler: handler.getUsersNotifications
    events:
      - http:
          method: GET
          path: /users/{userId}/notifications
          private: true
          request:
            parameters:
              paths:
                userId: true
  postUsersNotifications:
    handler: handler.postUsersNotifications
    events:
      - http:
          method: POST
          path: /users/{userId}/notifications
          private: true
          request:
            parameters:
              paths:
                userId: true


Copy and paste these into your handler.js file:

module.exports.getUsersNotifications = async () => {
  return {
    statusCode: 200,
    body: JSON.stringify({}),
  };
};

module.exports.postUsersNotifications = async () => {
  return {
    statusCode: 201,
  };
};

Dependencies (6)

Dev Dependencies (3)

Package Sidebar

Install

npm i generate-serverless-endpoints

Weekly Downloads

1

Version

1.1.0

License

ISC

Unpacked Size

5.58 kB

Total Files

4

Last publish

Collaborators

  • blewisio