For this assignment, you will build a REST API for artists for the operations described below.
Fetching artists
Create the endpoint GET /api/artists
which should return a collection of artist resources.
This endpoint will return all artists by default. There should be a query string parameter called q
that will filter down the list of artists returned by their name. For example, if I pass in q=the
, the list of artists returned will all have "the" (not "The") in their name. PostgresSQL is a case-sensitive database by default.
Creating an artist
Create the endpoint POST /api/artists
which should create an artist and return the created artist. The request payload should have a structure that matches the following:
{ "name": "Iya Terra" }
Validate that the name
is required. If validation fails, return the validation errors as JSON nested in an errors
key. The status code should be 422. Use Laravel's Validator class.
Deleting an artist
Create the endpoint DELETE /api/artists/{id}
which should delete an artist by its id
.
If the artist isn't found, return a 404 response.
This endpoint should delete an artist ONLY IF the artist doesn't have any tracks. If you aren't sure what query to run to apply this constraint, see this SQL query.
If the artist has tracks, return a 400 response with the following payload:
{
"error": "You cannot delete an artist that has tracks."
}
Submission
Verify that your app has been deployed to Heroku.
Send an email to Brighton and me with the URL to your GitHub repository with the subject: "ITP 405 - Assignment 9".