Skip to content

Commit 62c6e42

Browse files
committed
Merge remote-tracking branch 'origin/main'
2 parents a2426ef + 3909c10 commit 62c6e42

File tree

1 file changed

+69
-23
lines changed

1 file changed

+69
-23
lines changed

README.md

Lines changed: 69 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,73 @@
11
# API_Names
22

3-
API developed to search for a name by it's metaphone (br) on database and returns all similar names that it can found based on metaphone code and the levenshtein algorithm (0.8 of similarity).
3+
The API_Names project is designed to find a name and its possible variations from a given name, and correct any misspellings. It uses the Metaphone (br) algorithm to search the database and the Levenshtein distance method for correction.
44

5-
## Setup
6-
- create a MySql database, you can use [this script](https://github.com/Darklabel91/API_Names/blob/main/database/create_database.txt) if needed
7-
- set a .env file on the project with ```DB_USERNAME```, ```DB_PASSWORD```, ```DB_NAME```, ```DB_HOST``` and ```DB_PORT```
8-
- run the API ```go run main.go```
9-
- use import wizzard on mysql workbench to upload the [.csv file](https://github.com/Darklabel91/API_Names/blob/main/database/name_types.csv)
10-
- have fun
5+
## How to Run
116

12-
## API
13-
This project suports a simple CRUD. the main endpoint is ```/name``` where you can search for a name and it returns the name, metaphone code and all it's variations
7+
Before running the API, make sure you have MySQL installed on your machine. Then, create a .env file and set the following environment variables:
8+
```
9+
DB_USERNAME
10+
DB_PASSWORD
11+
DB_NAME
12+
DB_HOST
13+
DB_PORT
14+
SECRET
15+
```
16+
Finally, run the API using the command:
17+
```go
18+
go run main.go
19+
```
1420

15-
Every method expect Status:200 and JSON content-type as show bellow:
21+
## API Endpoints
22+
The main endpoint for the API is ```http://localhost:8080/metaphone/:name```. You need to log in to get an access token before you can access any other endpoint. We use JWT to generate access tokens.
1623

17-
| Req | Endpoint | Description | Success | Error |
18-
|--------|----------------------------------------|-------------------------------------|-------------------|--------------------|
19-
| POST | /name | Create a name in the database | Status:200 - JSON | Status: 400 - JSON |
20-
| DELETE | /:id | Delete a name by given id | Status:200 - JSON | Status: 404 - JSON |
21-
| PUT | /:id | Update a name by given id | Status:200 - JSON | Status: 500 - JSON |
22-
| GET | /:id | Read name with given id | Status:200 - JSON | Status: 400 - JSON |
23-
| GET | /name/:name | Read name with given name | Status:200 - JSON | Status: 404 - JSON |
24-
| GET | /metaphone/:name | Read metaphones of given name | Status:200 - JSON | Status: 404 - JSON |
24+
The following table shows the available endpoints, their corresponding HTTP methods, and a brief description:
25+
| Req | Endpoint | Description | Success | Error |
26+
|--------|----------------------------------------|-------------------------------------|-------------------|------------------------|
27+
| POST | /signup | Create a new user | Status:200 - JSON | Status: 400/401 - JSON |
28+
| POST | /login | Login user on API | Status:200 - JSON | Status: 400/401 - JSON |
29+
| POST | /name | Create a name in the database | Status:200 - JSON | Status: 400/401 - JSON |
30+
| DELETE | /:id | Delete a name by given id | Status:200 - JSON | Status: 404/401 - JSON |
31+
| PUT | /:id | Update a name by given id | Status:200 - JSON | Status: 500/401 - JSON |
32+
| GET | /:id | Read name with given id | Status:200 - JSON | Status: 400/401 - JSON |
33+
| GET | /name/:name | Read name with given name | Status:200 - JSON | Status: 404/401 - JSON |
34+
| GET | /metaphone/:name | Read metaphones of given name | Status:200 - JSON | Status: 404/401 - JSON |
2535

2636

2737
## Endpoint Examples
2838

29-
- GET - /3
39+
- POST - ```http://localhost:8080/signup```
40+
```json
41+
{
42+
"Email": "[email protected]",
43+
"Password": "123456"
44+
}
45+
```
46+
Return:
47+
```json
48+
{
49+
"Message": "User created",
50+
"User": {
51+
"ID": 2,
52+
"CreatedAt": "2023-03-28T23:18:23.624-03:00",
53+
"UpdatedAt": "2023-03-28T23:18:23.624-03:00",
54+
"DeletedAt": null,
55+
"Email": "[email protected]",
56+
"Password": "$2a$10$crIN3KKScm.HafCl9qQkzeehuK5XUfnGrAxCyymyMPnNHkwDwHBVS"
57+
}
58+
}
59+
```
60+
61+
- POST - ```http://localhost:8080/login```
62+
```json
63+
{
64+
"Email": "[email protected]",
65+
"Password": "123456"
66+
}
67+
```
68+
Return: ```status 200```
69+
70+
- GET - ```http://localhost:8080/3```
3071
```json
3172
{
3273
"ID": 3,
@@ -40,7 +81,7 @@ Every method expect Status:200 and JSON content-type as show bellow:
4081
}
4182
```
4283

43-
- GET - /name/aron
84+
- GET - ```http://localhost:8080/name/aron```
4485
```json
4586
{
4687
"ID": 3,
@@ -54,7 +95,7 @@ Every method expect Status:200 and JSON content-type as show bellow:
5495
}
5596
```
5697

57-
- GET - /metaphone/haron
98+
- GET - ```http://localhost:8080/metaphone/haron```
5899
```json
59100
{
60101
"ID": 3,
@@ -106,5 +147,10 @@ Every method expect Status:200 and JSON content-type as show bellow:
106147
]
107148
}
108149
```
109-
## Dependacy
110-
[metaphone-br](https://github.com/Darklabel91/metaphone-br)
150+
## Dependencies
151+
- [METAPHONE - BR](https://github.com/DanielFillol/metaphone-br)
152+
- [GIN](https://github.com/gin-gonic/gin)
153+
- [GORM](https://gorm.io)
154+
- [MySQL - GORM](https://github.com/go-gorm/mysql)
155+
- [GO.ENV](https://github.com/joho/godotenv)
156+
- [JWT](https://github.com/golang-jwt/jwt)

0 commit comments

Comments
 (0)