Skip to content

Niweera/25-days-of-serverless

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

25 Days of Serverless

Microsoft's 25 Days of Serverless Challenge but with Google Cloud Functions

API Documentation https://us-central1-fsuptutorial.cloudfunctions.net/api/api-docs/

Table of Contents

Challenge One

Paths

Location Endpoint
Root path https://us-central1-fsuptutorial.cloudfunctions.net/api/

HTTP request and query methods

Method Endpoint Description Examples
GET /one Get the random letter. one
{
  "letter": "ש"
}

Challenge Two:

Prerequisites

  1. PushBullet API KEY (To send push messages)
  2. Firebase Blaze Plan (To use Google Cloud Pub/Sub)

PoC

image image image image image image image image

Challenge Three

Prerequisites

  1. Firebase Blaze Plan

PoC

image

Challenge Four

API EndPoints are secured with Firebase Authentication.

PoC

Paths

Location Endpoint
Root path https://us-central1-fsuptutorial.cloudfunctions.net/api/four

HTTP request and query methods

Method Endpoint Access Description Examples
POST /register Public Register the user in the database. https://us-central1-fsuptutorial.cloudfunctions.net/api/four/register
POST /login Public User login. https://us-central1-fsuptutorial.cloudfunctions.net/api/four/login
POST /add Private Create food items in the database. https://us-central1-fsuptutorial.cloudfunctions.net/api/four/add
GET /list Private List the food items in the database. https://us-central1-fsuptutorial.cloudfunctions.net/api/four/list
PATCH /change Private Update the food items in the database. https://us-central1-fsuptutorial.cloudfunctions.net/api/four/change
DELETE /remove Private Delete the food items from the database. https://us-central1-fsuptutorial.cloudfunctions.net/api/four/remove

Database

image

Register

Send a POST request:

Request Body Payload

{
  "email": "EMAIL",
  "password": "PASSWORD",
  "returnSecureToken": true
}

Response Payload

{
  "idToken": "ID_TOKEN",
  "email": "EMAIL",
  "refreshToken": "REFRESH_TOKEN",
  "expiresIn": "EXPIRES_IN_TIME",
  "localId": "LOCAL_ID"
}

Login

Send a POST request:

Request Body Payload

{
  "email": "EMAIL",
  "password": "PASSWORD",
  "returnSecureToken": true
}

Response Payload

{
  "idToken": "ID_TOKEN",
  "email": "EMAIL",
  "refreshToken": "REFRESH_TOKEN",
  "expiresIn": "EXPIRES_IN_TIME",
  "localId": "LOCAL_ID",
  "registered": true
}

Create a Food Item

Send a POST request:

Request Header

Authorization: Bearer ID_TOKEN

Request Body Payload

{
  "dish_name": "DISH_NAME",
  "type": "TYPE",
  "amount": "AMOUNT"
}

Response Payload

{
  "message": "successfully added",
  "documentID": "DOCUMENT_ID"
}

List Food Items

Send a GET request:

Request Header

Authorization: Bearer ID_TOKEN

Response Payload

{
  "food_item_count": 1,
  "data": [
    {
      "email": "w.nipuna@gmail.com",
      "amount": "2 Kg",
      "type": "Dessert",
      "uid": "Ua6FZqUXaNNEtLnSfLjmKVIoeaR2",
      "dish_name": "Kokis"
    }
  ]
}

Update a Food Item

Send a PATCH request:

Request Header

Authorization: Bearer ID_TOKEN

Request Body Payload

{
  "dish_name": "DISH_NAME",
  "type": "TYPE",
  "amount": "AMOUNT",
  "document_id": "DOCUMENT_ID"
}

Response Payload

{
  "message": "Update successful"
}

Delete a Food Item

Send a DELETE request:

Request Header

Authorization: Bearer ID_TOKEN

Request Body Payload

{
  "document_id": "DOCUMENT_ID"
}

Response Payload

{
  "message": "Remove successful"
}

Challenge Five

Uses Cloud Natural Language API and Cloud Translation API

Prerequisites

  1. Google Billing Account

PoC

Request Body Payload

{
  "who": "Adam",
  "message": "my little brother is so annoying and stupid"
}

Response Payload

{
  "who": "Adam",
  "message": "my little brother is so annoying and stupid",
  "translation": "my little brother is so annoying and stupid",
  "detected_language": "en",
  "sentiment_magnitude": 0.800000011920929,
  "sentiment_score": -0.800000011920929,
  "naughty_or_nice": "Naughty"
}

Request Body Payload

{
  "who": "Adam",
  "message": "I really like the bike I got for a present"
}

Response Payload

{
  "who": "Adam",
  "message": "I really like the bike I got for a present",
  "translation": "I really like the bike I got for a present",
  "detected_language": "en",
  "sentiment_magnitude": 0.6000000238418579,
  "sentiment_score": 0.6000000238418579,
  "naughty_or_nice": "Nice"
}

Request Body Payload

{
  "who": "Eva",
  "message": "Eu odeio limpar meu quarto"
}

Response Payload

{
  "who": "Eva",
  "message": "Eu odeio limpar meu quarto",
  "translation": "I hate cleaning my room",
  "detected_language": "pt",
  "sentiment_magnitude": 0.6000000238418579,
  "sentiment_score": -0.6000000238418579,
  "naughty_or_nice": "Naughty"
}

Request Body Payload

{
  "who": "tracy",
  "message": "爸爸和圣诞老人​​很相似"
}

Response Payload

{
  "who": "tracy",
  "message": "爸爸和圣诞老人​​很相似",
  "translation": "Dad and Santa are very similar",
  "detected_language": "zh-CN",
  "sentiment_magnitude": 0.10000000149011612,
  "sentiment_score": 0.10000000149011612,
  "naughty_or_nice": "Nice"
}

Challenge Six

Uses Cloud Scheduler API

Prerequisites

  1. Google Billing Account
  2. Slack Workspace

PoC

image

Challenge Seven

Uses UNSPLASH Picture API with unsplash-js

Prerequisites

  1. Google Billing Account
  2. UNSPLASH Account

PoC

Request Body Payload

{
  "query": "gifts"
}

Response Payload

{
  "imageURLs": [
    "https://images.unsplash.com/photo-1511885912508-36118d773e55?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=1080&fit=max&ixid=eyJhcHBfaWQiOjEwNjI0Mn0",
    "https://images.unsplash.com/photo-1544654187-454deb2b423e?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=1080&fit=max&ixid=eyJhcHBfaWQiOjEwNjI0Mn0",
    "https://images.unsplash.com/photo-1511895307821-692dc4ad27c5?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=1080&fit=max&ixid=eyJhcHBfaWQiOjEwNjI0Mn0",
    "https://images.unsplash.com/photo-1448832945950-bc85f82891bd?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=1080&fit=max&ixid=eyJhcHBfaWQiOjEwNjI0Mn0",
    "https://images.unsplash.com/photo-1528029320621-f02197f47774?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=1080&fit=max&ixid=eyJhcHBfaWQiOjEwNjI0Mn0",
    "https://images.unsplash.com/photo-1461092678334-1aa3ab3543ce?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=1080&fit=max&ixid=eyJhcHBfaWQiOjEwNjI0Mn0",
    "https://images.unsplash.com/photo-1546813647-30583402ddd7?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=1080&fit=max&ixid=eyJhcHBfaWQiOjEwNjI0Mn0",
    "https://images.unsplash.com/photo-1544362724-a403d8211f89?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=1080&fit=max&ixid=eyJhcHBfaWQiOjEwNjI0Mn0",
    "https://images.unsplash.com/photo-1511953669874-6c617b315332?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=1080&fit=max&ixid=eyJhcHBfaWQiOjEwNjI0Mn0",
    "https://images.unsplash.com/photo-1573853019548-c38efdbc2f09?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=1080&fit=max&ixid=eyJhcHBfaWQiOjEwNjI0Mn0"
  ]
}

Challenge Eight

Uses ReactJS, Google Cloud Firestore for Client UI (with realtime data updates) and Google Firebase Functions (Uses Firebase Auth for API PATCH requests)

PoC

Update Delivery System Status

Send a PATCH request:

Request Header

Authorization: Bearer ID_TOKEN

Request Body Payload

{
  "status": "STATUS"
}

Response Payload

{
  "message": "Update successful"
}

Update ReinDeer Guidance System Status

Send a PATCH request:

Request Header

Authorization: Bearer ID_TOKEN

Request Body Payload

{
  "status": "STATUS"
}

Response Payload

{
  "message": "Update successful"
}

Client UI

image

Challenge Nine

Uses octokit/rest.js and Google Cloud Functions for Firebase

PoC

image

Challenge Ten

Still waiting for Twitter to review my Twitter developer account application.

Challenge Eleven

Uses Google Cloud Firestore and Algolia for full text search support

PoC

Send a request

POST /add

Request Body Payload

{
  "description": "I want a Tesla",
  "name": "Nipuna Weerasekara",
  "address": "Bad Route Rd, Terry, Mt 59349",
  "type": "Car"
}

Response Payload

{
  "message": "successfully added",
  "documentID": "DOCUMENT_ID"
}

Get all requests by Santa

GET /list

Response Payload

{
  "requests_count": 2,
  "data": [
    {
      "description": "I want a Tesla",
      "name": "Nipuna Weerasekara",
      "address": "Bad Route Rd, Terry, Mt 59349",
      "type": "Car"
    },
    {
      "description": "I want a Baby Yoda action figure",
      "name": "The Mandalorian",
      "address": "234, Millennium Falcon",
      "type": "Toy"
    }
  ]
}

Query a specific request by a keyword

GET /find/:query | /find/car

Response Payload

{
  "hits_count": 1,
  "data": [
    {
      "description": "I want a Tesla",
      "name": "Nipuna Weerasekara",
      "address": "Bad Route Rd, Terry, Mt 59349",
      "type": "Car"
    }
  ]
}