Skip to content

fahad0100/Example-of-building-a-Restful-API-in-the-Dart-

Repository files navigation

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:

Postman

Endpoints

Health Check

  • GET /
    Check if the server is running

Authentication

  • POST /api_v1/auth/signup

Create a new user account
Body

{
"name": "write name here ",
"email": "write email here",
"password": "write password here"
} 
  • POST /api_v1/auth/signin

Sign in to an existing user account
Body

{
"email": "write email here",
"password": "write password here"
} 
  • GET /api_v1/auth/checkauth

Check if the user's token is valid and not expired
The authorization header must contain a Token as bearer

<b> authorization : bearer eyJhbGc........... </b>
  • POST /api_v1/auth/resetpassword

Reset the password for a user account
Body

{
"email": "write email here",
} 

User

  • POST /api_v1/user/newpost

Create a new post
Body

{
    "title":"write title here",
    "content":"write content here"
}
  • 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/{here-idPost}

Retrieve a specific post by id

  • GET /api_v1/user/mypost/{here-idPost}

Retrieve a specific post by id that belongs to the current user

  • PUT /api_v1/user/updatepost/{here-idPost}

{
    "title":"write title here",
    "content":"write content here"
}

Update a specific post by id that belongs to the current user

  • DELETE /api_v1/user/deletepost/{here-idPost}

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:

  1. Clone the repository:
git clone https://github.com/fahad0100/Example-of-building-a-Restful-API-in-the-Dart-.git
  1. Change into the project directory:
cd Example-of-building-a-Restful-API-in-the-Dart-
  1. Install the dependencies:
dart pub get
  1. 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:

  1. Fork the repository.
  2. Create a new branch for your changes.
  3. Make your changes.
  4. Commit and push your changes to your branch.
  5. Open a pull request.

You can also contact me at [email protected] for further discussions.

Deployment

AliBaba cloud => http://8.213.24.202:8080
The API is hosted on GitHub
It has also been deployed on Heroku at Api

About

example of building a Restful API in the Dart

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published