Develop a RESTful API using Express.js framework backed by SQLite and Sequelize ORM. The API will serve as the backend for a platform where users can create chatbots. These chatbots will have conversations with end users.
Server: Express.js, Node.js
Database: SQLite
ORM: Sequelize
- ποΈ MVC Architecture for Organized Structure:: Implemented the Model-View-Controller (MVC) pattern to enhance code organization and separation of concerns. This modular approach allows for better maintainability and scalability.
- π Secure Handling with Environment Variables: Enhanced security and production readiness by utilizing environment variables to store sensitive information, such as database credentials, API keys, and JWT secret. Also implemented Password encyption for user while registering.
- π Smart Entity Manipulation Logic: Incorporated practical and efficient logics while handling entities. For instance, during user registration, the system intelligently checks whether the user already exists in the database. If found, the user is seamlessly logged in with a JWT token. If not, a new user is registered and a JWT token is generated for authentication.
- π Well-Defined Response Codes and Messages: Implemented clear and appropriate HTTP response codes and descriptive messages throughout the API. This ensures transparent communication between the API and clients, facilitating effective error handling and understanding of the application's behavior.
- π API Endpoint Design and Pagination (Bonus): Designed API endpoints following RESTful principles for structured interactions. Implemented pagination on endpoints that return lists of entities, enhancing performance and providing a more efficient user experience.
- π‘οΈ JWT Authentication and Authorization (Bonus): Incorporated JSON Web Tokens (JWT) for user authentication and authorization. This secure approach ensures that only authorized users can access protected routes and resources.
- Checks if user exits, if not then registers the user and send JWT Token, if exists, then logs in and send JWT Token.
POST http://localhost:5000/users
Send this as Body
Parameter | Type | Description |
---|---|---|
username |
string |
username |
email |
string |
email of user |
password |
string |
password of user |
- Fetches All Users and displays them in pagination format.
GET http://localhost:5000/users?page=1&limit=2
Send this as Query
Parameter | Type | Description |
---|---|---|
page |
integer |
current page |
limit |
integer |
limit of entries per page |
Send this as Headers
Parameter | Type | Description |
---|---|---|
authorization |
string |
Bearer TOKEN |
- Fetches a single User based on id
GET http://localhost:5000/users/:id
Send this as Headers
Parameter | Type | Description |
---|---|---|
authorization |
string |
Bearer TOKEN |
- Updates the details of user with particular Id.
PUT http://localhost:5000/users/:id
Send this as Body
Parameter | Type | Description |
---|---|---|
username |
string |
Updated username |
email |
string |
Updated email of user |
password |
string |
Updated password of user |
Send this as Headers
Parameter | Type | Description |
---|---|---|
authorization |
string |
Bearer TOKEN |
- Deletes the user with particular Id.
DELETE http://localhost:5000/users/:id
Send this as Headers
Parameter | Type | Description |
---|---|---|
authorization |
string |
Bearer TOKEN |
- Checks if user exists for particular Id, if yes then, checks if chatbot with given name and userId exists, if not, then creates a new chatbot for the userId, else send appropriate response.
POST http://localhost:5000/users/:userId/chatbots
Send this as Body
Parameter | Type | Description |
---|---|---|
name |
string |
Chatbot name |
Send this as Headers
Parameter | Type | Description |
---|---|---|
authorization |
string |
Bearer TOKEN |
- Fetches All Chatbots for particular user and displays them in pagination format.
GET http://localhost:5000/users/:userId/chatbots?page=1&limit=2
Send this as Query
Parameter | Type | Description |
---|---|---|
page |
integer |
current page |
limit |
integer |
limit of entries per page |
Send this as Headers
Parameter | Type | Description |
---|---|---|
authorization |
string |
Bearer TOKEN |
- Fetches a single chatbot based on chatbotId
GET http://localhost:5000/chatbots/:chatbotId
- Updates the details of chatbot with particular chatbotId.
PUT http://localhost:5000/chatbots/:chatbotId
Send this as Body
Parameter | Type | Description |
---|---|---|
name |
string |
Updated name of Chatbot |
userId |
string |
Updated userId of Chatbot |
- Deletes the chatbot with particular chatbotId.
DELETE http://localhost:5000/chatbots/:chatbotId
- Checks if chatbot exists for particular chatbotId, if yes then, creates a new conversation for that chatbot, else send appropriate response.
POST http://localhost:5000/chatbots/:chatbotId/conversations
Send this as Body
Parameter | Type | Description |
---|---|---|
content |
string |
Conversation Content |
endUserId |
string |
id of EndUser |
- Fetches All conversations for particular chatbot and displays them in pagination format.
GET http://localhost:5000/chatbots/:chatbotId/conversations?page=1&limit=2
Send this as Query
Parameter | Type | Description |
---|---|---|
page |
integer |
current page |
limit |
integer |
limit of entries per page |
- Fetches a single conversation based on conversationId
GET http://localhost:5000/conversations/:conversationId
- Updates the details of conversation with particular conversationId.
PUT http://localhost:5000/conversations/:conversationId
Send this as Body
Parameter | Type | Description |
---|---|---|
content |
string |
Updated Conversation Content |
chatbotId |
string |
Updated id of Chatbot |
endUserId |
string |
Updated id of EndUser |
- Deletes the conversation with particular conversationId.
DELETE http://localhost:5000/conversations/:conversationId
- Checks if end-user with particular email exits, if not then registers a new end-user. If already exists, then send appropriate response.
POST http://localhost:5000/endusers
Send this as Body
Parameter | Type | Description |
---|---|---|
name |
string |
name of EndUser |
email |
string |
email of EndUser |
- Fetches All EndUsers and displays them in pagination format.
GET http://localhost:5000/endusers?page=1&limit=2
Send this as Query
Parameter | Type | Description |
---|---|---|
page |
integer |
current page |
limit |
integer |
limit of entries per page |
- Fetches a single end-user based on endUserId
GET http://localhost:5000/endusers/:endUserId
- Updates the details of end-user with particular endUserId.
PUT http://localhost:5000/endusers/:endUserId
Send this as Body
Parameter | Type | Description |
---|---|---|
name |
string |
Updated name of endUser |
email |
string |
Updated email of endUser |
- Deletes the end-user with particular endUserId.
DELETE http://localhost:5000/endusers/:endUserId
- Github: @saksham9312
- Mail: [email protected]
- Phone: +917982613501