This project is a simple API I created to learn how to use the gin api routing and basic JSON reponses for a go API. It is not connected to database and the data is seeded by a local variable and store in said variable, meaning when you restart the service it will return to its default state. This is also ran on localhost using port 8000.
Start the application using:
go run .curl http://localhost:8000/albums[
{
"id": "1",
"title": "Appetite for Destruction",
"artist": "Guns N' Roses",
"price": 36.99
},
{
"id": "2",
"title": "Ten",
"artist": "Pearl Jam",
"price": 29.99
},
{
"id": "3",
"title": "London Calling",
"artist": "The Clash",
"price": 16.99
}
]curl http://localhost:8000/albums \
--include \
--header "Content-Type: application/json" \
--request "POST" \
--data '{"id": "4","title": "2112","artist": "Rush","price": 49.99}'{
"id": "4",
"title": "2112",
"artist": "Rush",
"price": 49.99
}Check to see if the new albums has been added to the albums slice
curl http://localhost:8000/albums[
{
"id": "1",
"title": "Appetite for Destruction",
"artist": "Guns N' Roses",
"price": 36.99
},
{
"id": "2",
"title": "Ten",
"artist": "Pearl Jam",
"price": 29.99
},
{
"id": "3",
"title": "London Calling",
"artist": "The Clash",
"price": 16.99
},
{
"id": "4",
"title": "2112",
"artist": "Rush",
"price": 49.99
}
]curl http://localhost:8000/albums/1{
"id": "2",
"title": "Ten",
"artist": "Pearl Jam",
"price": 29.99
}Will return error message if none is found
curl http://localhost:8000/albums/999{
"message": "album not found"
}