GithubHelp home page GithubHelp logo

fcm-server's Introduction

Firebase Cloud Messaging (FCM) Server for Notifications

๐Ÿš€ This Spring Boot application serves as a backend server for sending push notifications using Firebase Cloud Messaging.

Prerequisites

Before getting started, ensure that you have the following prerequisites installed:

  • Java Development Kit (JDK)
  • Maven
  • Firebase Project with FCM configuration

Getting Started

  1. Clone this repository:

    git clone https://github.com/MdShohanurRahman/fcm-server.git
    cd fcm-server
    
  2. Configure your Firebase project:

    • Obtain the google-services.json file from your Firebase project and place it in the src/main/resources directory.
  3. Build and run the application::

    mvn clean install
    java -jar target/your-fcm-server.jar
    

The server will start on http://localhost:8080.

Endpoints

1. Send Notification to Device

Endpoint: POST /api/v1/notifications/send-to-device

Example Request:

{
  "title": "Notification Title",
  "body": "Notification Message",
  "imageUrl": "https://cloudinary-marketing-res.cloudinary.com/images/w_1000,c_scale/v1679921049/Image_URL_header/Image_URL_header-png?_i=AA",
  "deviceToken": "dQcnK8K1BfwhNTyH81scC7:APA91bHC-O62Fz6kGQ1QnWkWdI7fs3O-Q7bLVs6HiX86IaphK2gO2aQwP62EFa64RbfAFBtbt5Y3AKLvW3IQq2cmQCzC6yzo-n3vH_E8ovCnIz2ykkHxqTDJx3SkOnS8MoorpVvPKwAE",
  "data": {
      "key1": "value1",
      "key2": "value2"
  }
}

2. Send Notification to Topic

Endpoint: POST /api/v1/notifications/send-to-topic

Example Request:

{
    "title": "Ind vs Nz world cup 2023",
    "body": "Ind won.",
    "topicName": "worldCup",
    "imageUrl": "https://cloudinary-marketing-res.cloudinary.com/images/w_1000,c_scale/v1679921049/Image_URL_header/Image_URL_header-png?_i=AA",
    "data": {
        "key1": "value1",
        "key2": "value2"
    }
}

3. Send Notification to All Devices

Endpoint: POST /api/v1/notifications/send-to-all

Example Request:

{
    "title": "Notification Title",
    "body": "Notification Message",
    "imageUrl": "https://cloudinary-marketing-res.cloudinary.com/images/w_1000,c_scale/v1679921049/Image_URL_header/Image_URL_header-png?_i=AA",
    "deviceTokenList": [], 
    "data": {
        "key1": "value1",
        "key2": "value2"
    }
}

4. Subscribe to Topic

Endpoint: POST /api/v1/notifications/subscribe

Example Request:

{
  "deviceToken": "dQcnK8K1BfwhNTyH81scC7:APA91bHC-O62Fz6kGQ1QnWkWdI7fs3O-Q7bLVs6HiX86IaphK2gO2aQwP62EFa64RbfAFBtbt5Y3AKLvW3IQq2cmQCzC6yzo-n3vH_E8ovCnIz2ykkHxqTDJx3SkOnS8MoorpVvPKwAE",
  "topicName": "worldCup"
}

5. Unsubscribe from Topic

Endpoint: POST /api/v1/notifications/unsubscribe

Example Request:

{
  "deviceToken": "dQcnK8K1BfwhNTyH81scC7:APA91bHC-O62Fz6kGQ1QnWkWdI7fs3O-Q7bLVs6HiX86IaphK2gO2aQwP62EFa64RbfAFBtbt5Y3AKLvW3IQq2cmQCzC6yzo-n3vH_E8ovCnIz2ykkHxqTDJx3SkOnS8MoorpVvPKwAE",
  "topicName": "worldCup"
}

Error Handling

  • If a request fails, the server will respond with an appropriate HTTP status code and an error message in the response body.

fcm-server's People

Contributors

mdshohanurrahman avatar

Stargazers

Minhazul Islam Rahat avatar

Watchers

 avatar

Forkers

tuanbeovnn

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.