Micronaut Demo Project
Take a look at a Micronaut-based REST API leveraging Result objects
Last updated
Was this helpful?
Take a look at a Micronaut-based REST API leveraging Result objects
Last updated
Was this helpful?
This demo project demonstrates how to handle and serialize Result
objects within a application. It provides a working example of a "pet store" web service that exposes a REST API for managing pets.
The project was generated via including features: annotation-api, http-client, openapi, serialization-jackson, swagger-ui, toml, and validation.
Then was manually added as a dependency to serialize and deserialize Result
objects.
That's all we need to do to make Micronaut treat results as .
API responses contain a Result
field, encapsulating the outcome of the requested operation.
Results have different success types, depending on the specific endpoint. Failures will be encapsulated as instances of ApiError
.
Controllers return instances of ApiResponse
that will be serialized to JSON by Micronaut:
Since failures are expressed as ApiError
objects, endpoints invariably return HTTP status 200
.
The application can be built and run with Gradle.
This will start a stand-alone server on port 8080.
Once started, you can interact with the API.
You should see a JSON response like this:
You can navigate to to inspect the API using an interactive UI.
The full source code for the example application is .