Ethan Hohensee
Ethan Hohensee

Reputation: 1557

Change Resource Path in Spring Data REST

With Spring Data REST, I'd like to change the path of a specific resource to be under a prefix i.e http://example.net/api/customprefix/myresource vs. http://example.net/api/myresource

I'm aware of how to change the base path of my Spring Data REST project using the spring.data.rest.base-path directive in application.properties, and this is currently set to /api

I have tried the following but I'm getting a 404 at http://example.net/api/customprefix/myresource

@RepositoryRestResource(path = "customprefix/myresource", collectionResourceRel = "myresources")
public interface MyResourceRepository extends PagingAndSortingRepository<MyResource, UUID> { }

Is it possible to set a custom prefix for a resource or group of resources with Spring Data REST?

Upvotes: 0

Views: 402

Answers (1)

Mirko Brandt
Mirko Brandt

Reputation: 475

What you want to do is not possible by design: you can read an extended version of why exactly here

Basically there is no reason why you would want to do this as the server or client doesn't need to know or understand the meaning of your URI. The customprefix has no meaning to the server or client whatsoever. You could just work with camel case or something like that to make your URI more readable.

In your case i.e. path = "customprefix-myresource".

Upvotes: 1

Related Questions