pporche87 / web-apis

Build a web API for the music player database

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

web-apis - Patrick Porche #minute-sifaka

Getting Started

How to Install

Install all dependencies in package.json

$ npm install

For more information regarding dependencies refer to the documentation at the following sites.

body-parser
express
morgan
nodemon
pg
pg-promise

How to Setup and Configure the Database

Run the following scripts in the command line to setup databases

$ npm run create-db

$ npm run seed-db

How to Run the Server

Run the following script in the command line to start the server

$ npm run start

Heroku Website Link and API

https://patrick-porche-web-apis.herokuapp.com/

Routes Definitions
Artists
// get all artists
// GET \ /artists

// get artist by id
// GET \ /artists/:id

// get artists by name
// GET \ /artists/name/:name

// create a new artist
// POST \ /new/:artist/:genre

// edit an artists name
// PUT \ /edit/:artist/:newArtist

// delete and artist
// DELETE \ /delete/:artist
Albums
// get all albums
// GET \ /albums

// get albums by id
// GET \ /albums/:id

// get albums by name
// GET \ /albums/name/:name

// create a new album
// POST \ /new/:album/:year

// edit an albums name
// PUT \ /edit/:album/:newAlbum

// delete album
// DELETE \ /delete/:album
Songs
// get all songs
// GET \ /songs

// get song by id
// GET \ /songs/:id

// get song by album
// GET \ /albums/name/:album_id

// get song by artist
// GET \ /new/:album/:artist_id

// create a new song
// POST \ /new/:title/:length/:track_no

// edit a songs name
// PUT \ /edit/:song/:newSong

// delete song
// DELETE \ /delete/:song
Playlists
// get all playlists
// GET \ /playlists

// get a playlist by id
// GET \ /playlists/:id

// get all songs in a playlist
// GET \ /songs/:title

// add a song to a playlist
// PATCH \ /new/song/:playlist/:song

// create a new playlist
// POST \ /new/:title/:songs

// edit a playlist
// PUT \ /edit/:playlist/:newPlaylist

// delete playlist
// DELETE \ /delete/:playlist 

Description

Build a web API for the music player database that you started working on in Init 4: Relational Databases.

In this goal, you’ll be putting all of the skills you’ve learned so far together to create a RESTful web API: JavaScript, Node.js, web servers with Express, and databases.

When you’re done, you’ll have a RESTful web API allowing consumers of the API to manage artists, albums, songs, and playlists on your music player app.

What is an API, you ask? API stands for Application Programming Interface. It’s a technical way of saying “the list of things you can tell a program to do”.

So, in the case of this application, your program is the music player application. It manages a music database containing artists, albums, songs, and playlists. The “list of things you can tell it to do” will include things like:

  • Get me all the artists
  • Get me songs in album X
  • Get me all songs in the playlist Y
  • Add a new album by artist X with title Y
  • Edit the name of song X
  • Delete song X from playlist Y

The API part is just the way to talk to and use a program, and you actually use APIs all the time. Whenever you use a module in Node.js, you are using that module’s API. Whenever you install and use a package from npm, you use that package’s API. The set of things that you can do with the DOM in the browser is called the DOM API.

When you build a web API, you’re providing a way to talk to a program through the internet using the HTTP protocol. That’s what you’re doing when you use the Twitter or GitHub web APIs.

Take a look at the resources provided for more background, guidance, and support in learning how to build web APIs with Node.js, Express, and PostgreSQL.

Terms & Concepts

Each day, pay attention to the terms & concepts highlighted in bold. By the end of the day, you should have a better idea of what they mean and how to use them. In other words, aim to be able to answer the question “what is X?” for yourself.

  • API (Application Programming Interface)
  • REST (Representational State Transfer) and RESTful design
  • HTTP request
  • HTTP response
  • HTTP request/response body and head
  • HTTP request methods: GET, POST, PUT/PATCH, DELETE (also called request verbs)
  • Web server
  • API client or consumer
  • Runtime environment: (common ones: development, production, test)
  • Deployment to a remote server
  • Database connection
  • Database query and query results
  • JSON data (JavaScript Object Notation)

Context

The series of refresher goals are designed for members of Learners Guild to challenge themselves to see what they can accomplish on their own.

Specifications

These are the basic specs for “Web APIs”. If you complete these specs, try taking on some of the Stretch specs.

General

  • Artifact is a repo on GitHub
  • Repo includes an Express.js app
  • App provide a command to start the web server
  • README includes “Getting Started” instructions
  • “Getting Started” instructs how to install
  • “Getting Started” instructs how to set up and configure the database
  • “Getting Started” instructs how to start the server
  • The artifact produced is properly licensed, preferably with the MIT license

Database

  • App uses PostgreSQL for data persistence
  • Database can store data about artists, albums, songs, and playlists
  • Database uses multiple tables with appropriate foreign keys
  • Database uses join tables for any many-to-many relationships
  • Artists have a name and genre
  • Albums have a title, artist, and year
  • Songs have a title, album, length (in seconds), and track number
  • Playlists have a title and are associated with a list of songs

API Specs

  • API employs a RESTful design
  • API returns JSON-formatted data
  • API accepts POST and PUT/PATCH requests with JSON-formatted bodies

Users of the API can…

  • Get all artists
  • Get an artist by id
  • Get an artist by name
  • Add a new artist
  • Edit an artist
  • Delete an artist
  • Get all albums
  • Get an album by id
  • Get an album by title
  • Add a new album
  • Edit an album
  • Delete an album
  • Get all songs
  • Get a song by id
  • Get all songs in an album
  • Get all songs by an artist
  • Add a new song
  • Edit a song
  • Delete a song
  • Get all playlists
  • Get a playlist by id
  • Get all songs in a playlist
  • Add a song to a playlist
  • Create a playlist
  • Edit a playlist
  • Delete a playlist

Deployment

  • App is deployed to Heroku
  • Link to deployed app is added to README
  • Deployed app uses Heroku Postgres for persistence
  • Deployed app provides the same API functionality as local version

Stretch

If you complete all of the specs listed above (the checkboxes), there’s no reason to stop there! Try building more advanced features with these stretch specs.

Users, Authentication & Authorization

  • Music player API requires authentication with username and password
  • API provides ways for users to “sign in” and “sign out”
  • Users have their own “library” of albums and playlists
  • Users can only see and interact with music in their own library

Music Player UI

  • App provides a single-page web UI.
  • UI uses JavaScript to fetch and send data from/to the API.
  • UI provides ways for users to view, create, edit, and delete Artists
  • UI provides ways for users to view, create, edit, and delete Albums
  • UI provides ways for users to view, create, edit, and delete Songs
  • UI provides ways for users to view, create, edit, and delete Playlists

Your Choice API

Pick another resource to build an API around. For example: a store with products in categories; an organization roster with employees and teams; a newspaper with articles, editions and writers.

  • App provides a RESTful JSON API
  • API manages at least 3 types of “resources” (i.e. it has at least 3 distinct tables in the database)
  • API allows users to read and create all 3 kinds of resources``

About

Build a web API for the music player database

License:MIT License


Languages

Language:JavaScript 100.0%