80smixtapeapi

command module
v0.0.0-...-633c506 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2019 License: MIT Imports: 8 Imported by: 0

README

80's Mixtape API

cassette tapes

The 80's mixtape API is a fun application that creates mixtapes of top pop hits from the 1980s. The project is built in GO and utilizes a Postgresql database. The project is dockerized and demonstrates some micro-services application strategies.

Author: Michael Babcock mjetpax@gmail.com

Coverage Status

Getting started

Getting started locally is simple. Make sure you have all the requirements on your local machine. Then run the Docker Compose commands in your terminal. Note, that Go is not required to run the dockerized application. It is only required for development.

Requirements
Local .env file

To run the app locally, you'll need to create an .env file with store environmental variables. An example.env file has been included. Run the following command and your done. Painless... I know.

cp example.env .env
Running with Docker Compose

Make sure you created a .env file as instructed above before proceeding. Note, that while developing & running with docker-compose, 80's Mixtape API will auto-compile and redeploy on script update (on save)... yay!

docker-compose up

This will launch the application and a development database. When the app is ready, you'll see this output 80's Mixtape API is listening on port 8080! in your terminal.

(Seriously, that's it.)

Use cURL to ping endpoints

Hit the health check endpoint with cUrl.

curl http://0.0.0.0:8080/health

For pretty formatted returns use jq. Example:

curl http://0.0.0.0:8080/health | jq .

Response:

{
  "application_name": "80's Mixtape API",
  "message": "80's Mixtape API is running smooth!",
  "start_date": "2019-01-04 23:18:11.826575403 +0000 UTC",
  "up_time": "4.300778317s"
}

API Endpoints

GET /health

Check the app's start date up time and other bits of info.

Examples:

curl http://0.0.0.0:8080/health

Example result:

{
  "application_name": "80's Mixtape API",
  "message": "80's Mixtape API is running smooth!",
  "start_date": "2019-01-04 23:18:11.826575403 +0000 UTC",
  "up_time": "4.300778317s"
}
GET /cassette/:cassette_type

cassette type is optional

The endpoint /cassette/:cassette_type is the main endpoint for this API. It creates a play list JSON response structured as if it were a cassette tape, with A and B sides. Optionally, pass along one of three cassette types, C60, C90, C120. Cassette types are used to indicate cassette tape storage capacity. For example, C90 indicates 90 minutes of playback time, 45 minutes per side. If excluded C60 is selected by default.

Examples:

curl http://0.0.0.0:8080/cassette

curl http://0.0.0.0:8080/cassette/C90

Example result:

{
  "tape_type": "C60",
  "side_a": {
    "songs": [
      {
        "id": 85,
        "title": "Karma Chameleon",
        "artist": "Culture Club",
        "year": 1984,
        "video": "https://music.youtube.com/watch?v=JvBInlDDQaU",
        "play_time": "4:21"
      },
      ...
    ],
    "play_time": "29:13"
  },
  "side_b": {
    "songs": [
      {
        "id": 56,
        "title": "I Can't Go For That",
        "artist": "Daryl Hall & John Oates",
        "year": 1982,
        "video": "https://music.youtube.com/watch?v=EHaJLvQgEOM",
        "play_time": "6:45"
      },
      ...
    ],
    "play_time": "27:39"
  }
}
GET /songs/:last_value/:limit

Paginate through the API's song catalog with calls to the /songs endpoint. Pagination uses the seek method. Include the last id value from the previous page and the page size limit with each GET request.

Example, walk through the song catalog with a page size of 10:

  • Page 1: curl http://0.0.0.0:8080/songs/0/10
  • Page 2: curl http://0.0.0.0:8080/songs/10/10
  • Page 3: curl http://0.0.0.0:8080/songs/20/10

A list of song objects will be returned as a JSON response.

[{
    "id": 1,
    "title": "Call Me",
    "artist": "Blondie",
    "year": 1980,
    "video": "https://music.youtube.com/watch?v=StKVS0eI85I",
    "duration_label": "2:15"
  },
  {
    "id": 2,
    "title": "Another Brick In The Wall",
    "artist": "Pink Floyd",
    "year": 1980,
    "video": "https://music.youtube.com/watch?v=HrxX9TBj2zY",
    "duration_label": "3:19"
  }]

Testing

Use this command for running unit tests.

go test -v ./...

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