Code Monkey home page Code Monkey logo

todoapi-serverless's Introduction

todoAPI-serverless

Creating a serverless API for the backend of a ToDo app with the serverless framework Automatically output Swagger json file to S3 bucket after deployment

Architecture

architecture

Requirement

  • serverlessframework
  • node
  • npm
  • pip3

Installation

$ npm install -g serverless

Usage

  1. Clone the repository & Install Library
$ git clone https://github.com/drumnistnakano/todoAPI-serverless.git
$ cd todoAPI-serverless
$ npm install
$ pip3 install -r requirements.txt
  1. Deploy

To deploy manually from local, execute the following sls command.

$ sls deploy --stage dev --region ap-northeast-1 # Deploy to development
$ sls deploy --stage prod --region ap-northeast-1 # Deploy to production

If you comment out the following part of serverless.yml, the manual deployment will succeed

org: drumnistnakano
app: todoapi
  1. (Option) CI/CD

It is possible to build a deployment pipeline using the CICD function of the Serverless Dashboard . You can easily execute build and test and automatically deploy to AWS environment.

After you create your account, run serverless login on the CLI to authenticate your CLI with the dashboard.

$ sls login
  1. Unit Test

Test code placed under the tests directory is executed.

$ pytest
  1. Run the API

Sign in with Cognito user pool to get ID Token(JWT) in advance. Using Cognito's Hosted UI, you can get an identity token (JWT) as shown in the following example.

https://www.example.com/#id_token=123456789tokens123456789&expires_in=3600&token_type=Bearer  

Execute the request with the ID Token as the value of the Authorization header.

# Create Todo
$ curl -XPOST  https://xxxxxxxxxxxx.execute-api.ap-northeast-1.amazonaws.com/{stage}/todos -H 'Authorization: edf2xxxxxxxxxxxxxxxxxxxxxx' -d'{"todoid": "0001", "title": "study", "content": "English"}'

# Get All Todo
$ curl -XGET https://xxxxxxxxxxxx.execute-api.ap-northeast-1.amazonaws.com/{stage}/todos -H 'Authorization: edf2xxxxxxxxxxxxxxxxxxxxxx'

# Get Single Todo
$ curl -XGET https://xxxxxxxxxxxx.execute-api.ap-northeast-1.amazonaws.com/{stage}/todos/0001 -H 'Authorization: edf2xxxxxxxxxxxxxxxxxxxxxx'

# Update Todo
$ curl -XPUT https://xxxxxxxxxxxx.execute-api.ap-northeast-1.amazonaws.com/{stage}/todos/0001 -H 'Authorization: edf2xxxxxxxxxxxxxxxxxxxxxx' -d'{"title": "study", "content": "mathematics"}'

# Delete Todo
$ curl -XDELETE https://xxxxxxxxxxxx.execute-api.ap-northeast-1.amazonaws.com/{/{stage}/todos/0001 -H 'Authorization: edf2xxxxxxxxxxxxxxxxxxxxxx'

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.