A robust and versatile REST API template with the setup of Authentication and User Management to streamline the process of creating REST APIs using Express.js.
It eliminates the need to write authentication code, saving you valuable time and effort. This template serves as an excellent starting point for any API requiring authentication, providing a secure and efficient foundation.
- π Specially designed to deploy on Vercel
Important
In this api every single file contains multiple components instead of being modularized because this API is designed to be deployed on Vercel. Vercel doesn't support more than 12 serverless functions, so to keep the JavaScript files under 12, I designed the API code this way.
Note
I developed this REST API to simplify the creation of APIs that require authentication. By using this template, developers can avoid writing authentication code, allowing them to focus on other essential aspects of their projects. This solution provides a comprehensive and efficient approach to creating REST APIs with user authentication.
- π September 2024
- Node.js
- Express.js
- MongoDB
- Express-Validator
- Node Mailer
Read Here
If you think you need a PC to start coding, think again! With just an Android phone, you can dive into the world of web and app development. Hereβs a showcase of a project created entirely on an Android phone using Acode, Restler, and Termux.
- Acode: A powerful code editor with features similar to VS Code, such as auto code completion, keyboard shortcuts, and theme customization.
- Restler: A REST API client for testing and debugging APIs similar to Postman.
- Termux: A terminal emulator for Android that allows you to run Linux commands and scripts.
- Hacker's Keyboard: A pc like Keyboard for Android that allows you to use commands like: Ctrl, Alt, F1, F2, (Up, Down, Right, Left Arrow) etc.
- Project in Acode Editor:
- Running the Project in Termux:
- Testing APIs with Restler:
- Portability: Code anytime, anywhere with just your phone.
- Convenience: No need to carry a laptop; everything you need is in your pocket.
- Efficiency: Get a lot done with minimal resources.
[!Note] With the right tools, learning and developing on an Android phone is not only possible but also an incredibly rewarding experience. Start your coding journey now!
- π Authentication: Secure user authentication and authorization.
- π Pagination & Sorting: Efficiently manage large data sets with pagination and sorting features.
- π Partial Response: Retrieve only the necessary data for optimized performance.
- π Secure with JWT: JSON Web Tokens for secure authentication.
- β Validation with Express-Validator: Ensure data integrity and correctness.
- π¦ Rate Limit: Protect against abuse and ensure fair usage.
- π§ Account Confirmation: Features for confirming user accounts before login.
- π Reset Password: Allow users to securely reset their passwords.
- π§ Change Email: Enable users to change their email with new email.
- π Change Password: Allow users to securely change their passwords.
- οΈπ Graceful Error Handling: Consistent and informative error responses.
- π Documentation: A comprehensive documentation with
swagger
. - π And Much More
Important
Please note that the API Documentation is currently a work in progress. Proper API documentation using Swagger is not yet complete. This means some endpoints may not be fully documented.
Note
Im working on completing this documentation to provide a more comprehensive guide for using This Api Template.
The API has not yet been deployed.
Ensure you have the following installed on your machine:
- Node.js
- Git
-
Clone the repository:
git clone https://github.com/fazle-rabbi-dev/Api-Template-With-Auth cd Api-Template-With-Auth
-
Install dependencies:
npm install
-
Set up environment variables:
Create a
.env
file in the root directory and add your configuration settings. For example:PORT=3000 MONGODB_URI= JWT_SECRET= ACCESS_TOKEN_SECRET= REFRESH_TOKEN_SECRET= ACCESS_TOKEN_EXPIRY="1d" REFRESH_TOKEN_EXPIRY="10d" GMAIL_USERNAME= GMAIL_PASSWORD=<Write your app password that you can get by enabling two factor auth in your gmail account> ENVIRONMENT=dev <For Seeding Purpose>
-
Customize Configuration: Modify the constants in
/src/index.js
to fit your specific needs. -
Run the server:
npm run dev
-
π The server will start on
http://localhost:3000
. -
Use a tool like Postman to interact with the API endpoints.
-
API base URL:
http://localhost:3000/api/
- AUTH Base URL:
base_url/auth
- USERS Base URL:
base_url/users
- SEEDING Base URL:
base_url/seed
- AUTH Base URL:
-
π API Documentation:
http://localhost:3000/api-docs
-
β‘ API Health Check:
http://localhost:3000/health
Contributions are welcome! π If you would like to contribute to This Api-Template, please follow these steps:
- Fork the repository: Click the "Fork" button at the top right of this page to create a copy of this repository under your GitHub account.
- Clone your fork: Clone your forked repository to your local machine.
git clone https://github.com/your-username/Api-Template-With-Auth
- Create a branch: Create a new branch for your feature or bugfix.
git checkout -b feature/your-feature-name
- Make your changes: Make your changes to the codebase.
- Commit your changes: Commit your changes with a clear and concise commit message.
git commit -m "Add your commit message here"
- Push to your branch: Push your changes to your forked repository.
git push origin feature/your-feature-name
- Create a Pull Request: Go to the original repository on GitHub and create a pull request from your forked repository. Provide a clear description of your changes and the reasons for them.
Your contributions will help make This Template even better. Thank you for your support! π
This project is licensed under the MIT License.
Thank you for using This Api-Template! I hope it accelerates your eCommerce development and makes your life easier. Happy coding! π
Let's connect! Reach out for collaborations, projects, or just a friendly chat.
Feel free to explore, contribute, and get inspired!