/serverless-now-node

"Serverless" CRUD API deployed using @zeit's now.

Primary LanguageTypeScript

Serverless Deployment w/ Zeit/now

CircleCI Test Coverage

exploring deploying "serverless" node apis with Now

Next Steps

Now that config and deployment seems to be working alright, next steps I believe would be to implement CRUD API operations with some sort of database.

  • Create → POST data
  • Read → GET data
  • Update → PUT / PATCH data
  • Delete → DELETE data

Implementing this, I think I would be building a public blog api with no auth.

Goals

Available Endpoints

Add New Post

POST api/v1/articles

Hitting this endpoint, anyone can create a new article (no auth required 🤞🏾).

Request Body Shape

{
  "body": {
    "title": "The Article's title 💪🏾",
    "body": "The body of the article 💪🏾",
    "author": "Author's name 🤤"
  }
}

Example Usage

curl \
  -X POST https://akhilome-snn.now.sh/api/v1/articles \
  -H "Content-Type: application/json" \
  -d '{
    "title":"Eternal 🎵🎼",
    "body":"Side chicks cant dance like this",
    "author":"Chance"
  }'

Get all Posts

GET api/v1/articles

Hitting this endpoint, anyone can get all articles

Example Usage

curl -X GET https://akhilome-snn.now.sh/api/v1/articles

Get Single Post

GET api/v1/articles/<id>

Hitting this endpoint, anyone can view the contents of a single article

Example Usage

curl -X GET https://akhilome-snn.now.sh/api/v1/articles/5d41689f2e9e3b07f0281170

Update a Post

PUT api/v1/articles/<id>

Hitting this endpoint, anyone can update the content of an article (but not the article's author)

Request Body Shape

{
  "body": {
    "title": "Updated Article Title ✍🏾",
    "body": "Updated article body 💥"
  }
}

Example Usage

curl \
  -X PUT https://akhilome-snn.now.sh/api/v1/articles/5d41689f2e9e3b07f0281170 \
  -H "Content-Type: application/json" \
  -d '{
    "title":"Eternal 🎵",
    "body":"Side chicks cant step like this"
  }'

Delete a Post

DELETE api/v1/articles/<id>

Hitting this endpoint, anyone can remove an article from the database

curl -X DELETE https://akhilome-snn.now.sh/api/v1/articles/5d41689f2e9e3b07f0281170

Important Notes

  • Lax error handling and input validation
  • No tests (yet)
  • Again, no auth 🤷🏾‍♂️

Tools

  • Now.sh
  • Typescript/Node
  • MongoDB (Mongoose as ODM)