Opened 7 years ago

Closed 5 years ago

#16691 closed defect (fixed)

[patch][cla] dojo.store.jsonrest cannot be used with REST servers that do support a trailing slash

Reported by: rhunwicks Owned by: Kris Zyp
Priority: low Milestone: 1.10
Component: Data Version: 1.8.3
Keywords: Cc:
Blocked By: Blocking:

Description

I am working on a project using OpenLayers? and Dojo. I want to use the same REST service as the target for both OpenLayers?.Protocol.HTTP and Dojo.Store.JsonRest?. Both OpenLayers?.Protocol.HTTP and my REST server assume the the target URL for the REST service will not have a trailing slash i.e. to the the list of objects we have:

/foo

and to get one object we have

/foo/123

Dojo.Store.JsonRest? assumes that the target has a trailing slash, i.e. to get the list of objects we have:

/foo/

Because of this assumption, Dojo.Store.JsonRest? just appends the id to the target when attempting a GET or PUT:

return xhr("GET", {
url: this.target + id,
handleAs: "json",
headers: headers
});

This means that I cannot use my default server URL of /foo because it attempts to get /foo123 instead of /foo/123

In the old dojox.data.JsonRestStore? this behaviour was configurable using the allowNoTrailingSlash property.

I think we should either introduce allowNoTrailingSlash to Dojo.Store.JsonRest? or infer it from the supplied target - if the target does not have a trailing slash, then get(), put(), add(), and remove() should add one automatically and query() should use the target as it was supplied.

If I wanted to submit a fix myself, should that be as a patch to this ticket, or as a PR in GitHub??

Change History (8)

comment:1 Changed 7 years ago by rhunwicks

Please see #8980 (dojox.rpc.Rest incorrectly adds trailing slash to target) for further background

Last edited 7 years ago by rhunwicks (previous) (diff)

comment:2 Changed 7 years ago by Kris Zyp

Should we automatically insert a slash if there is no trailing slash (and no query/question mark in the base url)?

We would prefer a patch, not a PR.

comment:3 Changed 7 years ago by rhunwicks

If the base URL doesn't contain a trailing slash then the methods that append an id - get(), put(), add(), and remove() - should insert a slash before the id.

I'll try and do a patch.

comment:4 Changed 5 years ago by dylan

Milestone: tbd1.10
Priority: undecidedlow

comment:5 Changed 5 years ago by dylan

Summary: dojo.store.jsonrest cannot be used with REST servers that do support a trailing slash[patch][cla] dojo.store.jsonrest cannot be used with REST servers that do support a trailing slash

comment:6 Changed 5 years ago by dylan

comment:7 Changed 5 years ago by dylan

A much simpler and probably more efficient solution would just be to normalize target to add the slash, rather than calling a function every time target is referenced (which is what the provided pull request does).

comment:8 Changed 5 years ago by Kris Zyp <kriszyp@…>

Resolution: fixed
Status: newclosed

In 7a0ebb945dbff2d96dae9cb736b0416b505e2f21/dojo:

Error: Processor CommitTicketReference failed
Unsupported version control system "git": Can't find an appropriate component, maybe the corresponding plugin was not enabled? 
Note: See TracTickets for help on using tickets.