This project demonstrates building a login API using the Go programming language and deploying it to the Heroku platform. The API allows users to log in and access "Rick and Morty" related data.
- Build a login API in Go.
- Implement endpoints for user registration, login, and accessing "Rick and Morty" data.
- Utilize Heroku for deployment and hosting.
Before you begin, ensure you have the following installed:
- Go (https://golang.org/)
- Heroku CLI (https://devcenter.heroku.com/articles/heroku-cli)
- Database (https://app.planetscale.com/)
-
Clone this repository:
git clone https://github.com/igorariza/go-rickandmorty-login.git cd go-rickandmorty-login
2. Install dependencies:
```sh
go mod download
-
Create a
.env
file in the root directory of the project. Add the following environment variablesPORT=8080 DB_HOST=host DB_PORT=port DB_USER=user DB_PASS=password DB_NAME=database DB_SSL=disable
-
Run the application locally:
go run main.go
-
Navigate to
http://localhost:8080/
or url heroku URL for a dev server. Navigate tohttps://go-rickandmorty-login-80476d397739.herokuapp.com/
GET {{url}}/api/v1/characters
[
{
"ID": 1,
"CreatedAt": "0001-01-01T00:00:00Z",
"UpdatedAt": "0001-01-01T00:00:00Z",
"DeletedAt": null,
"name": "Rick Sanchez",
"status": "Alive",
"species": "Human",
"gender": "Male",
"image": "https://rickandmortyapi.com/api/character/avatar/1.jpeg",
"created": "2017-11-04T18:48:46.250Z"
},
]
POST {{url}}/api/v1/users
{
"name": "John Doe",
"email": "johndoe@email.com",
"password": "admin",
"address": "Street 123",
"birthdate": "1990-01-01",
"city": "The world"
}
RESPONSE
{
"ID": 0,
"CreatedAt": "0001-01-01T00:00:00Z",
"UpdatedAt": "0001-01-01T00:00:00Z",
"DeletedAt": null,
"name": "John Doe",
"email": "johndoe@email.com",
"password": "",
"address": "Street 123",
"birthdate": "1990-01-01",
"city": "The world"
}
POST {{url}}/api/v1/login
{
"email": "johndoe@email.com",
"password": "admin"
}
RESPONSE
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6ImpvaG5kb2VAZW1haWwuY29tIiwiZXhwIjoxNjkyMjY2MjMxLCJwYXNzd29yZCI6IiJ9.8fiIJW5htHKNQiXRk-Ul1xAingYawXZDBPYWMFXnfuQ"
}
{
"success": true,
"status": 200,
"result": {
"CreatedAt": "0001-01-01T00:00:00Z",
"UpdatedAt": "0001-01-01T00:00:00Z",
"email": "johndoe@email.com",
}
}