Example of building a Restful API in the Dart
REST API using Dart
This API provides endpoints for authentication and managing user posts. It is built using the Dart programming language and connects to Firebase for authentication and MongoDB Atlas for storing data.
Prerequisites
- Dart SDK
- Firebase account and API credentials
- MongoDB Atlas account and cluster connection information
Postman workspace URL:
Endpoints
Health Check
- GET / Check if the server is running
Authentication
- POST /api_v1/auth/signup Create a new user account
- POST /api_v1/auth/signin Sign in to an existing user account
- GET /api_v1/auth/checkauth Check if the user’s token is valid and not expired
- POST /api_v1/auth/resetpassword Reset the password for a user account
User
- POST /api_v1/user/newpost Create a new post
- GET /api_v1/user/allposts Retrieve all posts
- GET /api_v1/user/myposts Retrieve all posts by the current user
- GET /api_v1/user/post/ Retrieve a specific post by id
- GET /api_v1/user/mypost/ Retrieve a specific post by id that belongs to the current user
- PUT /api_v1/user/updatepost/ Update a specific post by id that belongs to the current user
- DELETE /api_v1/user/deletepost/ Delete a specific post by id that belongs to the current user
Services
The project is connected to the following services:
- Firebase: For user authentication.
- MongoDB Atlas: For storing and retrieving data.
Set up
Set up your Firebase credentials
Create a file called firebase.json in the root of the project, and add your Firebase API key and other relevant information.
Running the API
To run the API, use the following command:
- Clone the repository:
git clone https://github.com/fahad0100/Example-of-building-a-Restful-API-in-the-Dart-.git
- Change into the project directory:
cd Example-of-building-a-Restful-API-in-the-Dart-
- Install the dependencies:
dart pub get
- Run the server:
dart bin/server.dart
Contributing
We welcome contributions to this project. If you have an idea for an improvement or a bug to report, please open an issue. If you would like to make a change yourself, please follow these steps:
- Fork the repository.
- Create a new branch for your changes.
- Make your changes.
- Commit and push your changes to your branch.
- Open a pull request.
You can also contact me at fahad.alazmi1994@gmail.com for further discussions.
Deployment
The API is hosted on GitHub It has also been deployed on Heroku at Api