HowToDoInJava

  • Python
  • Java
  • Spring Boot
  • Dark Mode
Home / RESTEasy / JAX-RS @Path URI Matching – Static and Regex URIs

JAX-RS @Path URI Matching – Static and Regex URIs

Learn to use JAX-RS @Path annotation and write resource path in it for URI matching. Paths can be written in simple form (static or path parameter) or complex form (regex based).

1. JAX-RS @Path URI Matching Types

JAX-RS @Path annotation is used to specify the URI on which the resources will be accessible to other applications or clients. The @javax.ws.rs.Path annotation must exist on either the class and/or a resource method. If it exists on both the class and method, the relative path to the resource method is a concatenation of the class and method.

URIs in @Path are defined in two ways.

  1. Simple URI matching
  2. Regex based URI matching

2. JAX-RS @Path – Simple URI matching

In simplest form, URI consist of static path and if needed some per-defined parameters.

  • @Path ("users") – matches to application/user-management/users.
  • @Path ("users/{id}") – matches to application/user-management/users/12.

3. JAX-RS @Path – Regex based URI matching

In complex form, we can use regular expression based parameter matching.

  • @Path("/users/{id: [0-9]*}") (support digit only) – matches to http://localhost:8080/RESTfulDemoApplication/user-management/users/123456.
  • @Path("/users/{id: [a-zA-Z][a-zA-Z_0-9]}") (first character alphabet and then alpha-numerics) – matches to http://localhost:8080/RESTfulDemoApplication/user-management/users/abc123.
Download source code

Happy Learning !!

Was this post helpful?

Let us know if you liked the post. That’s the only way we can improve.

Share this:

  • Twitter
  • Facebook
  • LinkedIn
  • Reddit

About Lokesh Gupta

A family guy with fun loving nature. Love computers, programming and solving everyday problems. Find me on Facebook and Twitter.

Feedback, Discussion and Comments

  1. gani

    January 7, 2014

    how to prevent displaying null attributes in json response when using jersey jax rs

    • Lokesh Gupta

      January 7, 2014

      Use primitives. Primitives don’t have default values while object does have i.e. null. It means use int in stead of Integer.

Comments are closed on this article!

Search Tutorials

RESTEasy Tutorial

  • JAX-RS – Introduction
  • RESTEasy – JBoss
  • RESTEasy – Tomcat
  • RESTEasy – @Path
  • RESTEasy – HATEOAS
  • RESTEasy – SLF4J
  • RESTEasy – Log4j
  • RESTEasy – Download
  • RESTEasy – Upload (MultipartForm)
  • RESTEasy – Upload (HTTPClient)
  • RESTEasy – Custom Validation
  • RESTEasy – Hibernate Validator
  • RESTEasy – ContainerRequestFilter
  • RESTEasy – PreProcessorInterceptor
  • RESTEasy – JAXB XML
  • RESTEasy – Jettison JSON
  • RESTEasy – Jackson JSON
  • RESTEasy – ExceptionMapper

RESTEasy Client APIs

  • RESTEasy – java.net
  • RESTEasy – JAX-RS Client
  • RESTEasy – Apache HttpClient
  • RESTEasy – JavaScript API
  • RESTEasy – ResteasyClientBuilder

RESTEasy Best Practices

  • RESTEasy – Sharing Context Data
  • RESTEasy – Exception Handling
  • RESTEasy – ETag Cache control
  • RESTEasy – GZIP Compression
  • RESTful vs. SOAP

Meta Links

  • About Me
  • Contact Us
  • Privacy policy
  • Advertise
  • Guest and Sponsored Posts

Recommended Reading

  • 10 Life Lessons
  • Secure Hash Algorithms
  • How Web Servers work?
  • How Java I/O Works Internally?
  • Best Way to Learn Java
  • Java Best Practices Guide
  • Microservices Tutorial
  • REST API Tutorial
  • How to Start New Blog

Copyright © 2020 · HowToDoInjava.com · All Rights Reserved. | Sitemap

  • Java 15 New Features
  • Sealed Classes and Interfaces
  • EdDSA (Ed25519 / Ed448)