Giter Club home page Giter Club logo

serverless-api-demo's Introduction

Serverless TypeScript API With Momento Serverless Cache

This tutorial shows a basic serverless TypeScript REST API using DynamoDB (AWS) or Firestore (GCP) supercharged with Momento Serverless Cache. It contains a serverless application that can be built and deployed with CDK in AWS or Pulumi in GCP. The API is supposed to represent a basic users api. It contains the following endpoints:

# Generate base users in authoritative store to use for test 
POST /bootstrap-users

# Get single user from authoritative store
GET /users/1
# Get single user from cache
GET /cached-users/1

# Get passed user's follower names from authoritative store
GET /followers/1
# Get passed user's follower names from cache
GET /cached-followers/1

POST /bootstrap-users

Bootstraps all the test user data needed. For this demo it generates 100 test users each following 5 random other test users.

GET /users & /cached-users

Makes 1 call to DB (/users) or Momento (/cached-users)

$ curl $API_URL/cached-users\?id\=1 -s | jq .
{
  "id": "1",
  "followers": [
    "63",
    "60",
    "81",
    "18",
    "60"
  ],
  "name": "Happy Sloth"
}

In case you don't have it already, jq is a great tool for working with JSON.

GET /followers & /cached-followers

Will make a call to either DB (/followers) or Momento (/cached-followers) for the passed user id and then five additional calls (in series) to either DB or Momento to look up each follower name.

$ curl https://x949ucadkh.execute-api.us-east-1.amazonaws.com/Prod/cached-followers/1 -s
["Dumb Rabbit","Excited Wombat","Lazy Squirrel","Lazy Sloth","Strange Rabbit","Lazy Squirrel","Mystical Dog","Strange Cat","Dumb Dog","Excited Dog","Clingy Lion","Strange Frog","Strange Rabbit","Lazy Frog","Happy Sloth","Happy Sloth","Sad Cat","Clingy Cat","Happy Sloth","Obnoxious Fish","Excited Lion","Spacey Frog","Goofy Dog","Goofy Dog","Happy Hamster","Obnoxious Dog","Sad Cat","Obnoxious Lion","Happy Sloth","Obnoxious Otter","Angry Dog","Sad Rabbit","Excited Fish","Dumb Hamster","Clingy Otter","Angry Dog","Happy Hamster","Happy Hamster","Clingy Hamster","Happy Sloth","Happy Dog","Spacey Wombat","Clingy Lion","Clingy Sloth","Clingy Hamster","Rare Lion","Spacey Wombat","Angry Rabbit","Mystical Zebra","Excited Frog","Happy Dog","Angry Dog","Spacey Wombat"]%

To deploy and benchmark this demo in AWS please continue here!

To deploy and benchmark this demo in GCP please continue here!

serverless-api-demo's People

Contributors

eaddingtonwhite avatar ijin avatar kvcache avatar nosqlknowhow avatar pete-naylor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

ijin

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.