HTTP endpoint (REST-API)
overview
Deal with raw HTTP requests and responses, on the client and on the server. This mimics the creation and use of a regular REST API.
The server API resembles the ExpressJS API.
We respond with JSON or HTML.
export const sayHello = onRequest((req, res) => {
res.send("Hello from Firebase!")
})
options argument
const options = {
region: ""
cors: true,
}
export const sayHello = onRequest(options, (req, res) => {});
ExpressJS concepts and syntax
We may use middleware. Req and res objects have the shape of an expressJS req and res objects.
Build a REST request
This is not specific to firebase. From a web client, we may use fetch().
We may provide a payload and specify the method as POST.