steniowagner / expo-notifications-api

A RESTful API built with NodeJS + TS to send push notifications to Expo apps.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

# expo-notifications-api

Preview-Screens

This is the back-end of the expo-notifications-app and expo-notifications-dashboard.

The main purpose of this API is:

OBS: This API just delivers the notifications to the Expo servers using expo-server-sdk and handle the errors that may occurs alog the way. The responsability to deliver the notifications to the final users is the FCM for Android and APNs for Apple, and is up to Expo the responsability to deliver the notifications to FCM and APNs, so, maybe you find some delay until your notifications been delivered to the users due some problem like overload on the provider's server or expo's servers (usually it's just a matter of wait a little bit 😛).

About this Project

This project is part of my personal portfolio, so, I'll be happy if you could provide me any feedback about the project, code, structure or anything that you can report that could make me a better developer!

Email-me: stenio.wagner1@gmail.com

Connect with me at LinkedIn

Also, you can use this Project as you wish, be for study, be for make improvements or earn money with it!

It's free!

Getting Started

Prerequisites

To run this project in the development mode, you'll need to have a basic environment with NodeJS 8+ installed. To use the database, you'll need to have MongoDB installed and running on your machine at the default port (27017).

If you have Docker installed, there's a docker-compose file with the setup for the database and server (which is the default setup for this project).

Installing

Cloning the Repository

$ git clone https://github.com/steniowagner/expo-notifications-api

$ cd expo-notifications-api

Installing dependencies

$ yarn

or

$ npm install

Running the Development environment

If you want to run the server using Docker, you can setup the container using the following command:

$ docker-compose -f docker-compose.development.yml up

If you do prefer run the database and the app without Docker, do the following instead:

  • Replace the database string for the address of the MongoDB running on your network on .env.development file.
  • Make sure to inject the NODE_ENV=development variable, you can do this by editing the dev script and adding this command in the front of the script:
"dev": "NODE_ENV=development nodemon src/app.ts",

With all dependencies installed and the environment properly configured, you can now run the server:

$ yarn dev

or

$ npm run dev

Routes

The base path for the API is /expo-notifications/api/v1

Test Route

  • This is the route that you can use to check if the API is running properly.

http://localhost:4000/expo-notifications/api/v1

ENDPOINT Method Params URL Params Success Response Error Response
/ GET - - Code: 200 - OK
Content: { message: "UHUL! The API is UP && RUNNING!" }
Code: 500 - INTERNAL SERVER ERROR
Content: { message: <A Message with a description of the Error> }

CRUD User

  • GET /users - Get all users
  • GET /users/:id - Get a single user
  • POST /users - Create an user (Need to provide the User inside the body of the request)
  • PUT /users/:id - Update an user (Need to provide the User fields to be updated inside the body of the request)
  • DELETE /users/:id - Delete a single user

Send Notifications

ENDPOINT Method Params URL Params Success Response Error Response
/push-notifications POST { tokens: [string], title: string, body: string] } - Code: 200 - OK
Content: PushNotificationResponse
Code: 500 - INTERNAL SERVER ERROR
or
Code: 400 - BAD REQUEST
Content: { message: <A Message with a description of the Error> }

Entities

PushNotificationResponse

usersNotRegistered: Users that uninstalled the App from their devices and have been deleted from the database due that, so the app will not send notifications to them anymore.

shippingErrors: Some errors that may happen along the way, you can find more about the errors here and the implementation of the error-handler for each error here and here.

{
  "usersNotRegistered": [{
    "user": "User"
  }],
  "shippingErrors": [{
    "reason": "string",
    "user": "User"
  }],
}

User

name: User's name.

email: User's email.

notificationToken: User's notification push token provided by Expo.

{
  "name": {
    "type": "string",
    "required": true,
  },
  "email": {
    "type": "string",
    "required": true,
  },
  "notificationToken": {
    "type": "string",
    "required": true,
  },
}

Built With

Contributing

You can send how many PR's do you want, I'll be glad to analyse and accept them! And if you have any question about the project...

Email-me: stenio.wagner1@gmail.com

Connect with me at LinkedIn

Thank you!

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

About

A RESTful API built with NodeJS + TS to send push notifications to Expo apps.

License:MIT License


Languages

Language:TypeScript 96.0%Language:JavaScript 3.1%Language:Dockerfile 0.9%