Categorygithub.com/Darklabel91/API_Names
modulepackage
0.0.0-20231006183139-e08dff8f0a3f
Repository: https://github.com/darklabel91/api_names.git
Documentation: pkg.go.dev

# README

API_Names

The API_Names project is an API 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.

Features

  • JWT Authentication
  • Limited access by Token
  • Sign-up
  • Login
  • Log local and imported to the database from time to time
  • Middleware

Requirements

Before running the API, make sure you have MySQL installed on your machine.

Installation and Setup

  1. Clone the repository
  2. Create a .env file at the root of your project and set the following environment variables:
DB_USERNAME=<your_username>
DB_PASSWORD=<your_password>
DB_NAME=<your_database_name>
DB_HOST=<your_database_host>
DB_PORT=<your_database_port>
SECRET=<your_jwt_secret>

Replace the values with your own database credentials and a secret for JWT token generation. Worht to mention that the DB_NAME does not require an existing database.

  1. Finally, run the API using the following command:
go run main.go

On the first run, the prompt will return:

go run main.go
2023/04/12 18:48:48 -   Created Database
2023/04/12 18:48:48 -   Upload data start
2023/04/12 18:49:21 -   Upload data finished 33.113701109s
2023/04/12 18:49:21 -   Created first user
2023/04/12 18:49:21 -   Listening and serving...

API Endpoints

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.

The following table shows the available endpoints, their corresponding HTTP methods, and a brief description:

ReqEndpointDescriptionSuccessError
POST/signupCreate a new userStatus:200 - JSONStatus: 400/401 - JSON
POST/loginLogin user on APIStatus:200 - JSONStatus: 400/401 - JSON
POST/nameCreate a name in the databaseStatus:200 - JSONStatus: 400/401 - JSON
DELETE/:idDelete a name by given idStatus:200 - JSONStatus: 404/401 - JSON
PUT/:idUpdate a name by given idStatus:200 - JSONStatus: 500/401 - JSON
GET/:idRead name with given idStatus:200 - JSONStatus: 400/401 - JSON
GET/name/:nameRead name with given nameStatus:200 - JSONStatus: 404/401 - JSON
GET/metaphone/:nameRead metaphones of given nameStatus:200 - JSONStatus: 404/401 - JSON

Endpoint Examples

  • POST - http://localhost:8080/signup
{
    "Email": "[email protected]",
    "Password": "123456"
}

Return:

{
    "Message": "User created",
    "User": {
        "ID": 2,
        "CreatedAt": "2023-04-12T18:48:48.475-03:00",
        "UpdatedAt": "2023-04-12T18:48:48.475-03:00",
        "DeletedAt": null,
        "Email": "[email protected]",
        "Password": "$2a$10$crIN3KKScm.HafCl9qQkzeehuK5XUfnGrAxCyymyMPnNHkwDwHBVS"
    }
}
  • POST - http://localhost:8080/login
{
    "Email": "[email protected]",
    "Password": "123456"
}

Return: status 200

{
    "Message": "Login successful"
}
  • GET - http://localhost:8080/3
{
  "ID": 3,
  "CreatedAt": "2023-04-12T18:48:48.475-03:00",
  "UpdatedAt": "2023-04-12T18:48:48.475-03:00",
  "DeletedAt": null,
  "Name": "ARON",
  "Classification": "M",
  "Metaphone": "ARM",
  "NameVariations": "|AARON|AHARON|AROM|ARON|ARYON|HARON|"
}
  • GET - http://localhost:8080/name/aron
{
  "ID": 3,
  "CreatedAt": "2023-04-12T18:48:48.475-03:00",
  "UpdatedAt": "2023-04-12T18:48:48.475-03:00",
  "DeletedAt": null,
  "Name": "ARON",
  "Classification": "M",
  "Metaphone": "ARM",
  "NameVariations": "|AARON|AHARON|AROM|ARON|ARYON|HARON|"
}
  • GET - http://localhost:8080/metaphone/haron
{
    "ID": 3,
    "CreatedAt": "2023-04-12T18:48:48.475-03:00",
    "UpdatedAt": "2023-04-12T18:48:48.475-03:00",
    "DeletedAt": null,
    "Name": "ARON",
    "Classification": "M",
    "Metaphone": "ARM",
    "NameVariations": "ARON | AROM | AARON | ARYON | HARON | AHARON | "
}

Dependencies

Extra

If you're interested in checking out my API caller, you can find it by clicking on this link

# Packages

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author