Your server environment and FCM
The server side of Firebase Cloud Messaging consists of two components:
- The FCM backend provided by Google.
- Your app server or other trusted server environment where your server logic runs, such as Cloud Functions for Firebase or other cloud environments managed by Google.
Your app server or trusted server environment sends message requests to the FCM backend, which then routes messages to client apps running on users' devices.
Requirements for the trusted server environment
Your app server environment must meet the following criteria:
- Able to send properly formatted message requests to the FCM backend.
- Able to handle requests and resend them using exponential back-off.
- Able to securely store server authorization credentials and client registration tokens.
Choosing a server option
You'll need to decide on a way to interact with FCM servers: either using the Firebase Admin SDK or the raw protocol. Because of its support across popular programming languages and its convenience methods for handling authentication and authorization, the Firebase Admin SDK is the recommended method.
Options for interacting with FCM servers include the following:
- The Firebase Admin SDK, which has support for Node, Java, Python, C#, and Go.
- The FCM HTTP v1 API, a REST API with secure authorization and flexible cross-platform messaging capabilities (the Firebase Admin SDK is based on this protocol and provides all of its inherent advantages).
Firebase Admin SDK for FCM
The Admin FCM API handles authenticating with the backend and facilitates sending messages and managing topic subscriptions. With the Firebase Admin SDK, you can:
- Send messages to individual devices
- Send messages to topics and condition statements that match one or more topics.
- Subscribe and unsubscribe devices to and from topics
- Construct message payloads tailored to different target platforms
The Admin Node.js SDK provides methods for sending messages to device groups.
To set up the Firebase Admin SDK, see Add the Firebase Admin SDK to Your Server. If you already have a Firebase project, start with Add the SDK. Also, make sure to enable the Cloud Messagin API in the in the Cloud Messaging settings page for your project. Then, once the Firebase Admin SDK is installed, you can start writing logic to build send requests.
FCM server protocol
FCM provides the FCM HTTP v1 API for developers who prefer a raw server protocol.
To send a message, the app server issues a POST request with an HTTP header and an HTTP body comprised of JSON key value pairs. For details on the header and body options, see Build App Server Send Requests