saule icon indicating copy to clipboard operation
saule copied to clipboard

relative url for links object

Open luke-zhang opened this issue 8 years ago • 3 comments

is there a way to return relative url for links object. in our projects, we'd like to see this "links": { "self": "/api/sessions" }, instead of
"links": { "self": "http://localhost:49895/api/sessions" },

luke-zhang avatar Apr 13 '17 05:04 luke-zhang

This is not possible at the moment, but I'm open to a PR to allow this.

The request URI comes from here:

https://github.com/joukevandermaas/saule/blob/41c9b84a0158bfa2b633e4023a15f2a24e8dcc0d/Saule/Http/PreprocessingDelegatingHandler.cs#L59

It's then passed into the serializer here:

https://github.com/joukevandermaas/saule/blob/41c9b84a0158bfa2b633e4023a15f2a24e8dcc0d/Saule/JsonApiSerializer.cs#L73

It's prepended to every generated path here:

https://github.com/joukevandermaas/saule/blob/41c9b84a0158bfa2b633e4023a15f2a24e8dcc0d/Saule/Serialization/ResourceSerializer.cs#L318

I think a property GenerateRelativeUrls in JsonApiSerializer (default value: false) is a nice backwards-compatible spot to put this.

joukevandermaas avatar Apr 13 '17 07:04 joukevandermaas

@joukevandermaas thanks a lot for your help. I am thinking if IUrlPathBuilder is better than JsonApiSerializer to place this property since it can be customized easily.

luke-zhang avatar Apr 13 '17 07:04 luke-zhang

I agree with you, but it currently does not have this behavior. So that would be breaking backwards compatibility. If you can think of a way to not break existing stuff, I'm all for it.

joukevandermaas avatar Apr 13 '17 08:04 joukevandermaas