Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
bkawk committed Feb 8, 2023
1 parent 6f54324 commit 4423210
Show file tree
Hide file tree
Showing 4 changed files with 183 additions and 2 deletions.
76 changes: 74 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,75 @@
# go-echo
# Go-Echo Boilerplate API

basic api for all things user auth and registration
A pre-built REST API project that combines Go and the Echo framework to provide a simple yet robust foundation for developers.

## Introduction

Go-Echo Boilerplate API is designed to be a fast and efficient solution for building RESTful APIs. The [Echo](https://echo.labstack.com/) framework is known for its performance, scalability, and ease of use. With this boilerplate, you can take advantage of Echo's lightning-fast routing and middleware support to build APIs that can handle large amounts of traffic with ease. Whether you're building a high-performance application or just need to get up and running quickly, Go-Echo provides a foundation that is both fast and reliable. By leveraging the power of Go and the Echo framework, you can ensure that your API will perform at peak efficiency and provide a smooth experience for your users.

## Key Features

- User authentication and authorization
- MongoDB Atlas integration
- Rate limiting
- Body size limit
- Secure middleware
- CORS support
- Email verification
- Password reset

## Requirements
- Go
- Echo
- MongoDB Atlas
- SMTP Server (e.g. Gmail, SendGrid, etc.)

## Getting Started

1. Clone this repository
2. Make sure you have Go installed on your machine
3. Set up a MongoDB Atlas cluster and obtain your connection string
4. Create a .env file in the root of the project and add the following variables:


- PORT: The port on which the server will run, e.g. :8000
- MONGO_URL: The connection string for your MongoDB Atlas cluster, e.g. mongodb+srv://<username>:<password>@cluster0.mongodb.net/test?retryWrites=true&w=majority
- MONGO_DB: The name of the database, e.g. databaseName
- BCRYPT_PASSWORD: The bcrypt password, e.g. bcryptPassword
- EMAIL_FROM: The email address from which emails will be sent, e.g. [email protected]
- SMTP_SERVER: The SMTP server used for sending emails, e.g. smtp.example.com
- SMTP_PORT: The port used for the SMTP server, e.g. 587
- SMTP_PASSWORD: The password for the SMTP server, e.g. password
- JWT_SECRET: The secret used for signing JSON Web Tokens (JWT), e.g. jwtSecret
- VERIFY_URL: The URL used for email verification, e.g. http://example.com/verify
- RESET_EMAIL_URL: The URL used for resetting the email, e.g. http://example.com/reset-email
```
5. Run the following command to install the dependencies:
``` go get ```
6. Run the following command to start the server:
``` go run main.go ```
## Endpoints
- [Health Check](health_check.md): GET /health
- [User Registration](user_registration.md): POST /register
- [Check username availability](username_availability.md): GET /username/:username
- [Login](login.md): POST /login
- [Refresh Token](refresh_token.md): POST /refresh
- [Invalidate Token](invalidate_token.md): POST /invalidate
- [Password Reset](password_reset.md): POST /reset-password
- [Update Profile](update_profile.md): PUT /profile
- [Retrieve Profile](retrieve_profile.md): GET /profile/:user_id
- [Verify Email](verify_email.md): GET /verify/:token
- [Resend Verification Email](resend_verification.md): POST /resend-verification
## How to Contribute
If you would like to contribute to the project, please follow these steps:
1. Fork the repository
2. Create a new branch for your contribution
3. Commit your changes to the new branch
4. Submit a pull request to the original repository
5. We welcome all contributions, including bug fixes, new features, and documentation 6. improvements. Thank you for your support!
24 changes: 24 additions & 0 deletions login.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Login Endpoint

This endpoint is used to handle user login requests.

## Request

The following table describes the required parameters for a login request:

| Parameter | Type | Description |
|-----------|------|-------------|
| email | string | The email address of the user. |
| username | string | The username of the user. |
| password | string | The password of the user. |

## Response

A successful request returns a JSON object with the following properties:

| Property | Type | Description |
|----------|------|-------------|
| jwtToken | string | A JSON Web Token that can be used to authenticate subsequent requests. |
| refreshToken | string | A refresh token that can be used to generate a new JWT token. |

A failed request returns a JSON object with an error property that describes the error.
32 changes: 32 additions & 0 deletions password_reset.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# ResetPasswordPost Endpoint

This endpoint handles user password reset requests.

## Request

The endpoint accepts a JSON request with the following fields:

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `PasswordResetToken` | string | Yes | A unique token sent to the user's email to reset their password |
| `Password` | string | Yes | The new password to be set |

## Responses

The endpoint returns a JSON response with the following fields:

### Success

The request was successful, and the password has been reset.

| HTTP Status | Response |
|-------------|----------|
| 200 OK | `Password successfully reset` |

### Errors

The request failed for the following reasons:

| HTTP Status | Response |
|-------------|----------|
| 400 Bad Request | `Invalid Reset token or user not verified`
53 changes: 53 additions & 0 deletions user_registration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Register Endpoint

The `RegisterPost` endpoint handles user registration requests.

## Request

The endpoint accepts JSON payload with the following parameters:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| username | string | Yes | The desired username of the user. |
| email | string | Yes | The email address of the user. |
| password | string | Yes | The password of the user. |

Example request body:

```
{
"username": "john.doe",
"email": "[email protected]",
"password": "secretpassword"
}
```

## Response

The endpoint returns a JSON response with the following properties:

| Property | Type | Description |
|----------|------|-------------|
| message | string | Success message if the account was created successfully. |
| error | string | Error message if there was a problem creating the account. |

### Success Response

HTTP 200 OK is returned with the following JSON payload:

```
{
"message": "Your account has been successfully created"
}
```

### Error Responses

| HTTP Status Code | Error Type | Description |
|------------------|------------|-------------|
| 400 Bad Request | Validation Error | Occurs when the input data does not meet the requirements |
| 400 Bad Request | Duplicate Data Error | Occurs when the username or email is already taken |
| 500 Internal Server Error | Hash Password Error | Occurs when the password hash generation fails |
| 500 Internal Server Error | Generate UUID Error | Occurs when generating a unique identifier fails |
| 500 Internal Server Error | Save User Error | Occurs when saving the user to the database fails |
| 500 Internal Server Error | Email Error | Occurs when sending an email fails |

0 comments on commit 4423210

Please sign in to comment.