saule
saule copied to clipboard
relative url for links object
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" },
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 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.
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.