API_Names

command module
v0.0.0-...-e08dff8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 6, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

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:

Req Endpoint Description Success Error
POST /signup Create a new user Status:200 - JSON Status: 400/401 - JSON
POST /login Login user on API Status:200 - JSON Status: 400/401 - JSON
POST /name Create a name in the database Status:200 - JSON Status: 400/401 - JSON
DELETE /:id Delete a name by given id Status:200 - JSON Status: 404/401 - JSON
PUT /:id Update a name by given id Status:200 - JSON Status: 500/401 - JSON
GET /:id Read name with given id Status:200 - JSON Status: 400/401 - JSON
GET /name/:name Read name with given name Status:200 - JSON Status: 404/401 - JSON
GET /metaphone/:name Read metaphones of given name Status:200 - JSON Status: 404/401 - JSON

Endpoint Examples

  • POST - http://localhost:8080/signup
{
    "Email": "user@user.com",
    "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": "user@user.com",
        "Password": "$2a$10$crIN3KKScm.HafCl9qQkzeehuK5XUfnGrAxCyymyMPnNHkwDwHBVS"
    }
}
  • POST - http://localhost:8080/login
{
    "Email": "user@user.com",
    "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

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL