Skip to content

Latest commit

 

History

History

lesson_26

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Lesson 26: Web APIs using REST (Slides)

Pre-work

Please review the following resources before lecture:

Required

Recommended

Homework

Creating a Library API

We are continuing to build atop the foundation of our library app. For this assignment, you will help implement the API that will be used by a yet-to-come front-end app.

  • You will implement the MediaItemsController to enable the following API:
    • GET /items - Retrieves a list of media items
    • POST /items - Creates a new media item
    • GET /items/:id - Retrieves a single media item with the given ID.
    • DELETE /items/:id - Deletes a single media item with the given ID.
  • Study the tests in MediaItemsControllerTest to understand what you should accept and return in the API.
  • You should not need to make any code changes outside of the com.codedifferently.lesson26.web package.

Running the API

You can run the server using the usual ./gradlew run command from the api/java directory. If you want to test that the server is running correctly, you can use curl like so:

curl http://localhost:3001/items | json_pp

The project also includes an OpenAPI user interface (Swagger) for navigating the API. Just visit http://localhost:3001/swagger-ui.html to access it.

Alternatively, you can also test the API using the tool Postman. I recommend installing this tool to make it easier to test things.

Debugging the API

Remember that you can debug the API by visiting the main function in Lesson26.java and clicking Debug main. You'll be able to set breakpoints in your code to see what's happening and fix issues.

Debugging the API

TypeScript API

This project also includes a fully functioning TypeScript version of the Java project. You can visit api/javascript/api_app to execute it using npm start and view the OpenAPI documentation at http://localhost:3000/api (note that it runs on port 3000).

Additional resources