Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

relative url for links object #144

Open
luke-zhang opened this issue Apr 13, 2017 · 3 comments
Open

relative url for links object #144

luke-zhang opened this issue Apr 13, 2017 · 3 comments

Comments

@luke-zhang
Copy link

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" },

@joukevandermaas
Copy link
Owner

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

The request URI comes from here:

return jsonApi.PreprocessContent(content, resource, request.RequestUri);

It's then passed into the serializer here:

baseUrl: requestUri,

It's prepended to every generated path here:

var start = new Uri(_baseUrl.GetLeftPart(UriPartial.Authority).EnsureEndsWith("/"));

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

@luke-zhang
Copy link
Author

@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.

@joukevandermaas
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants