code-differently-24-q4

Lesson 26: Web APIs using REST (Slides)

Pre-work

Please review the following resources before lecture:

Required

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.

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