API Survey #2 - Firebase Realtime Database

Cara Wang <caraw@cnyes.com>

API Survey #2

Firebase Realtime Database

@author Cara Wang <caraw@cnyes.com>

@since 2016/11/24

The Goal of API Survey

What is RESTful API ?

Review: What is REST ?

Review: What is REST ?

  1. Simplicity
  2. Scalability
  3. Reliability
  4. Performance

Review: What is REST ?

  1. Modifiability
  2. Visibility

Review: What is REST ?

Review: What is REST ?

  1. The 5 constraints (or characteristics):
    1. Client-Server

Review: What is REST ?

  1. The 5 constraints (or characteristics):
    1. Layered System

Review: What is REST ?

  1. The 5 constraints (or characteristics):

Review: What is REST ?

  1. The 5 constraints (or characteristics):

Review: What is REST ?

  1. The 5 constraints (or characteristics):
    1. Stateless

Review: What is REST ?

  1. The 5 constraints (or characteristics):

The Affection to API Design

Interface / Uniform Contract

Method Verb Description
GET Read Read one or more specific resource(s)
POST Create Create one or more specific resource(s)
PUT / PATCH Update Update one or more specific resource(s)
DELETE Remove Remove one or more specific resource(s)

The Effection to the API Design

Interface / Uniform Contract

			GET /users
			GET /users/lasutung
			POST /news
			PUT /news/1
			DELETE /users/lasutung/news/1 ??
			DELETE /news/1 # Simplicity
			DELETE /news/1,2,3
		

The Effection to the API Design

Interface / Uniform Contract

The Effection to the API Design

Interface / Uniform Contract

The Effection to the API Design

  1. Idempotent: Can do it over and over again without causing different results
Method Idempotent
GET Yes
POST No
PUT Yes
PATCH No
DELETE Yes
https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html

Firebase

Founded on Apr 6, 2011

Firebase Realtime Database API

HTTP Method

Method Firebase RESTful API
GET Reading Data Read
POST Pushing Data Create
PUT Writing Data Update
PATCH Updating Data Update
DELETE Removing Data Remove

Firebase Realtime Database API

			https://{your-project-name}.firebaseio.com
			/{your-firebase-model-lv-1}
			/{your-firebase-model-lv-2}
			...
			.json
		

Firebase Realtime Database API

Firebase Realtime Database API

  1. HTTP Status Code
    1. Success: 200 OK

Firebase Realtime Database API

  1. Response Payload

Firebase Realtime Database API

  1. Response Payload
    1. Success:

Pros and Cons

Pros and Cons

  1. Pros
    1. 使用 HTTP Status Code 做溝通
    2. Payload 有 error 的 Key 時,HTTP Status Code 必定不是 2xx
    3. 一致用 200 代表成功,不會有其他 2xx 的可能
Demo

Q & A

Fork me on GitHub