go-albums-api is a simple API written in Golang using the Gin web framework. This API comes from the official Golang tutorial; it was my first contact with the language. This API allows users to manage a collection of albums, where each album has an ID, title, artist, list of musics, and price.
https://github.com/yan-pi/go-albums-api/
GET /albums
Returns a list of all albums stored in the API.
- Status Code: 200 OK
- Body:
[ { "id": "1", "title": "Dialogos", "artist": "Bardek", "musics": ["Dialogos", "Agora", "Amanhã", "Sempre"], "price": 19.99 } ]
GET /albums/:id
- id: The ID of the album to retrieve.
Returns the album with the specified ID.
-
Status Code: 200 OK
-
Body:
{ "id": "1", "title": "Dialogos", "artist": "Bardek", "musics": ["Dialogos", "Agora", "Amanhã", "Sempre"], "price": 19.99 }
-
Status Code: 404 Not Found
-
Body:
{ "message": "album not found" }
POST /albums
{
"id": "2",
"title": "New Album",
"artist": "New Artist",
"musics": ["Song1", "Song2"],
"price": 9.99
}
Adds a new album to the collection.
- Status Code: 201 Created
- Body:
{ "id": "2", "title": "New Album", "artist": "New Artist", "musics": ["Song1", "Song2"], "price": 9.99 }
To run the API, execute the following command:
go run main.go
After running the command, the API will start and listen on localhost:8080
.
This is a simple API for managing a collection of albums using Golang and Gin. You can use the provided endpoints to get all albums, get an album by ID, and add a new album to the collection.