Skip to content
This repository has been archived by the owner on Jun 29, 2022. It is now read-only.

Latest commit

 

History

History
62 lines (45 loc) · 2.4 KB

README.md

File metadata and controls

62 lines (45 loc) · 2.4 KB

⚠️ Nodejs 8 is no longer supported by Firebase. To use Node 11 you have to add payment method. The concept described here should apply to Node 11 as well, minor modification may be required.


firebase-mock-api-server

A simple mock API server using Express.js that is hosted on Firebase.

Why custom mock server

You have full control of what API to define and what data to respond with with minimal coding.

How it works

See medium article https://link.medium.com/OAjz9kkV0U on how to setup firebase project and setup mock server.

Show me examples

The APIs are defined via Express.js framework and served though Firebase cloud functions. All the defined API can be found at 👉 functions/index.js 👈 and pre-loaded mock responses example can be found at mock-responses

Simple GET

https://mock-apis-server.firebaseapp.com/say/hello

https://mock-apis-server.firebaseapp.com/say/hello?name=Ryan

Capture data from URL

https://mock-apis-server.firebaseapp.com/users/myid

POST data to register new account

Success

curl -X POST \
  https://mock-apis-server.firebaseapp.com/register \
  -H 'Content-Type: application/json' \
  -d '{"userId": "myusername", "email":"my@email.com", "name": "New User"}'

Fail

curl -X POST \
  https://mock-apis-server.firebaseapp.com/register \
  -H 'Content-Type: application/json' \
  -d '{"userId": "taken", "email":"existing@email.com", "name": "Existing User"}'

NOTE: You will have to use terminal to execute these curl commands.

Large list of photos response from mocked JSON file

https://mock-apis-server.firebaseapp.com/photos

Single photo item from mocked JSON file

https://mock-apis-server.firebaseapp.com/photos/29647

Use 🔥 Firebase Firestore database

Using firebase console you can easily update the database values to reflect new values in realtime without needing to touch JSON source files.