Skip to content

Commit

Permalink
more docs
Browse files Browse the repository at this point in the history
  • Loading branch information
bkawk committed Feb 8, 2023
1 parent 95572e1 commit b7636f1
Show file tree
Hide file tree
Showing 9 changed files with 234 additions and 10 deletions.
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Go-Echo Boilerplate API is designed to be a fast and efficient solution for buil

- 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]
Expand All @@ -53,17 +54,18 @@ Go-Echo Boilerplate API is designed to be a fast and efficient solution for buil
``` go run main.go ```

## Endpoints
- [Health Check](health_check.md): GET /health
- [User Registration](user_registration.md): POST /register
- [Health Check](health.md): GET /health
- [Check username availability](username_availability.md): GET /username/:username
- [Register](register.md): POST /register
- [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
- [Reset Password](password_reset.md): POST /reset-password
- [Refresh Token](refresh_token.md): POST /refresh
- [Invalidate Refresh Token](invalidate_token.md): DELETE /refresh

- [Update Profile](update_profile.md): PUT /profile ***
- [Retrieve Profile](retrieve_profile.md): GET /profile/:user_id ***

## How to Contribute
If you would like to contribute to the project, please follow these steps:
Expand Down
6 changes: 3 additions & 3 deletions api/handlers/refresh.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type PostResponse struct {
// RegisterEndpoint handles user registration requests
func RefreshPost(c echo.Context) error {
// Get the refreshToken from the request
refreshToken := c.Param("refreshToken")
refreshToken := c.FormValue("refreshToken")
// Get database connection from context
db := c.Get("db").(*mongo.Database)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
Expand Down Expand Up @@ -67,8 +67,8 @@ type DeleteResponse struct {
// RegisterEndpoint handles user registration requests
func RefreshDelete(c echo.Context) error {

// Get the current refreshToken from the request header
refreshToken := c.Request().Header.Get("Authorization")
// Get the refreshToken from the request
refreshToken := c.FormValue("refreshToken")

// Get database connection from context
db := c.Get("db").(*mongo.Database)
Expand Down
8 changes: 8 additions & 0 deletions api/handlers/refresh.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Your request headers, e.g.
POST http://localhost:8080/refresh/
Content-Type: application/json

# The request body, if any
{
"refreshToken": "token here",
}
19 changes: 19 additions & 0 deletions health.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Health Endpoint

## Get Health Status

### Request

`GET /health`

### Response

#### Success

- Status Code: 200 OK
- Content:

```json
{
"status": "OK"
}
37 changes: 37 additions & 0 deletions invalidate_token.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Refresh Delete Endpoint Error Responses

The `RefreshDelete` endpoint may return the following error responses in case of a failure.

## Responses

The endpoint returns a JSON object with the following fields:

| Field | Type | Description |
|------------|--------|-----------------------------------------------------------------------|
| Message | string | A string indicating the status of the request. Can be an error message. |

### HTTP 400 Bad Request

When the provided `refreshToken` is invalid, the endpoint returns the following response:


```
HTTP 400 Bad Request
{
"Message": "Invalid refresh token"
}
```

### HTTP 500 Internal Server Error

In case of a failure to update the user in the database, the endpoint returns the following response:


```
HTTP 500 Internal Server Error
{
"Message": "Failed to update user in database"
}
```
51 changes: 51 additions & 0 deletions refresh_token.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Endpoint: RefreshPost

Refreshes a JWT for a user with a valid refresh token.

## Request

Method | Endpoint | Description
-------|----------|------------
POST | /refresh | Refreshes a JWT for a user with a valid refresh token

### Request Body

Field | Type | Required | Description
------|------|----------|------------
refreshToken | string | Yes | Refresh token of the user

## Response

HTTP Code | Response Body | Description
----------|---------------|------------
200 | `{"message": "Success", "data": {"jwt": "<jwt>"}}` | If the JWT was successfully refreshed
400 | `{"message": "Invalid refresh token"}` | If the provided refresh token is invalid
500 | `{"message": "Failed to find user in database"}` | If there was a problem finding the user in the database
500 | `{"message": "Failed to generate JWT"}` | If there was a problem generating the JWT

### Response Body

Field | Type | Description
--------|--------|------------
message | string | Status message
data | object | JSON object with the refreshed JWT

## Example

Request:

```
POST /refresh
Content-Type: application/x-www-form-urlencoded
refreshToken=<refresh_token>
```

Response:

```
HTTP/1.1 200 OK
Content-Type: application/json
{"message": "Success", "data": {"jwt": "<jwt>"}}
```
File renamed without changes.
70 changes: 70 additions & 0 deletions username_availability.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Check Username Endpoint

## Get a user's availability by checking their username

### Request

`GET /check-username?username=<username>`

### Parameters

| Name | Type | Description |
| ---- | ---- | ----------- |
| username | string | Required. The username to check availability for |

### Response

Success:
```
HTTP/1.1 200 OK
Content-Type: application/json
{
"message": "Username available",
"available": true
}
```

or

```
HTTP/1.1 200 OK
Content-Type: application/json
{
"message": "Username not available",
"available": false
}
```

### Error Responses

| HTTP Code | Description |
| --------- | ----------- |
| 400 Bad Request | If the query parameter `username` is missing |
| 500 Internal Server Error | If an error occurs while checking the username in the database |

### Response

Bad Request:

```
HTTP/1.1 400 Bad Request
Content-Type: application/json
{
"message": "Username is required"
}
```

Internal Server Error:

```
HTTP/1.1 500 Internal Server Error
Content-Type: application/json
{
"message": "An error occurred while checking the username",
"error": "<error message>"
}
```
37 changes: 37 additions & 0 deletions verify_email.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Verify Email

Verifies an email using the provided `verificationCode` as a query parameter in the URL.

#### Endpoint

```
GET /verify-email?verificationCode=<verificationCode>
```

#### URL Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| verificationCode | string | Required. The verification code used to verify the email. |

#### Success Response

Status Code: 200 OK

```
{
"message": "User marked as verified successfully!"
}
```

#### Error Responses


The following table lists the possible error responses for the `GET /verify-email` endpoint:

| HTTP Status Code | Error Code | Description |
| --- | --- | --- |
| 500 Internal Server Error | `Failed to verify the user` | The verification failed due to a server-side error. |
| 500 Internal Server Error | `Invalid verification code` | The provided `verificationCode` is invalid. |


0 comments on commit b7636f1

Please sign in to comment.