DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Spring Boot, Quarkus, or Micronaut?
  • Custom Validators in Quarkus
  • Java REST API Frameworks
  • High-Performance Reactive REST API and Reactive DB Connection Using Java Spring Boot WebFlux R2DBC Example

Trending

  • Unlocking Data with Language: Real-World Applications of Text-to-SQL Interfaces
  • How the Go Runtime Preempts Goroutines for Efficient Concurrency
  • Blue Skies Ahead: An AI Case Study on LLM Use for a Graph Theory Related Application
  • How to Practice TDD With Kotlin
  1. DZone
  2. Coding
  3. Frameworks
  4. Build a REST API With Just 2 Classes in Java and Quarkus

Build a REST API With Just 2 Classes in Java and Quarkus

Quarkus enables a full CRUD API with just two classes using Hibernate ORM with Panache. No controllers or repositories needed — just define two classes, and deploy.

By 
Otavio Santana user avatar
Otavio Santana
DZone Core CORE ·
Mar. 13, 25 · Tutorial
Likes (15)
Comment
Save
Tweet
Share
10.8K Views

Join the DZone community and get the full member experience.

Join For Free

Developers often look for ways to build RESTful APIs with minimal effort while maintaining clean and maintainable code. Quarkus enables a fully functional CRUD (Create, Read, Update, Delete) API using just two classes.

With Hibernate ORM with Panache, Quarkus simplifies entity management, and REST Data with Panache automatically exposes a complete set of RESTful endpoints. This approach reduces the time spent on boilerplate code, allowing developers to focus on business logic rather than infrastructure.

This article demonstrates building a developer management API in Java using Quarkus. We will also cover how to interact with the API using cURL commands, showcasing the efficiency of this approach.

Why Quarkus?

Quarkus is a lightweight, cloud-native Java framework for performance and developer productivity. It reduces boilerplate code while maintaining the power of Java and Jakarta EE.

We can simplify entity management with Hibernate ORM with Panache, and with REST Data with Panache, we can expose a full CRUD API without writing a controller class!

Why Use Quarkus for REST APIs?

Quarkus is designed for efficiency, productivity, and performance. It provides:

  • Minimal code. Automatic REST API generation reduces the need for controllers.
  • Fast development. Live coding  quarkus:dev allows instant feedback.
  • Optimized for cloud. Lower memory footprint and faster startup times.
  • Seamless integration. Works effortlessly with microservices and cloud-native architectures.

With these advantages, developers can quickly build and deploy high-performance applications with minimal effort.

Step 1: Create the Entity

Our API will manage developers with basic attributes like name, email, language, and city.

We define the entity using PanacheEntity, which automatically provides an id field and simplifies data access.

Java
 
package expert.os.videos.quarkus;

import io.quarkus.hibernate.orm.panache.PanacheEntity;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;

@Entity
public class Developer extends PanacheEntity {

    @Column
    public String name;

    @Column
    public String email;

    @Column
    public String language;

    @Column
    public String city;
}


How It Works

  • The @Entity annotation marks this class as a JPA entity.
  • Extending PanacheEntity automatically provides an id and built-in CRUD operations.
  • Each field is mapped to a database column with @Column.

Since Quarkus manages the database interactions, no additional repository classes are required.

Step 2: Create the REST API in One Line

Instead of writing a full controller class, we can expose a REST API by creating an interface that extends PanacheEntityResource.

Java
 
package expert.os.videos.quarkus;

import io.quarkus.hibernate.orm.rest.data.panache.PanacheEntityResource;

public interface DevelopersResource extends PanacheEntityResource<Developer, Long> {
}


How It Works

By extending PanacheEntityResource<Developer, Long>, Quarkus automatically generates endpoints for:

  • GET/developers → Retrieve all developers
  • GET/developers/{id} → Retrieve a specific developer
  • POST/developers → Create a new developer
  • PUT/developers/{id} → Update an existing developer
  • DELETE/developers/{id} → Delete a developer

With just two classes, a complete CRUD API is available.

Step 3: Run the Application

Make sure you have Quarkus installed and set up in your project.

Start the Quarkus application with:

Shell
 
./mvnw compile quarkus:dev


Step 4: Test the API With cURL

Once the application is running, we can interact with the API using cURL.

Create a developer (POST request):

Shell
curl -X POST http://localhost:8080/developers \
     -H "Content-Type: application/json" \
     -d '{
           "name": "Alice",
           "email": "[email protected]",
           "language": "Java",
           "city": "Lisbon"
         }'


Get all developers (GET request):

Shell
curl -X GET http://localhost:8080/developers


Get a single developer by ID (GET request):

Shell
curl -X GET http://localhost:8080/developers/1


Conclusion

Quarkus significantly simplifies building REST APIs in Java, reducing the need for extensive boilerplate code while maintaining flexibility and performance. Using Hibernate ORM with Panache and REST Data with Panache, we could expose a fully functional CRUD API using just two classes — a domain entity and a resource interface.

This approach eliminates the need for manually implementing repository classes or defining explicit REST controllers, allowing developers to focus on business logic rather than infrastructure. The result is a more concise, maintainable, and efficient API that integrates seamlessly with modern cloud-native architectures.

For teams and developers looking to accelerate application development while maintaining the robustness of Java, Quarkus presents a compelling solution. Organizations can reduce complexity and improve productivity without sacrificing scalability by adopting its developer-friendly approach and efficient runtime.


API Quarkus REST Java (programming language) Framework

Opinions expressed by DZone contributors are their own.

Related

  • Spring Boot, Quarkus, or Micronaut?
  • Custom Validators in Quarkus
  • Java REST API Frameworks
  • High-Performance Reactive REST API and Reactive DB Connection Using Java Spring Boot WebFlux R2DBC Example

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • [email protected]

Let's be friends: