Skip to content

Instantly share code, notes, and snippets.

@sebastienblanc
Last active December 16, 2015 02:28
Show Gist options
  • Save sebastienblanc/5362225 to your computer and use it in GitHub Desktop.
Save sebastienblanc/5362225 to your computer and use it in GitHub Desktop.

Hi,

Today when we set up a Pipe and call methods on it, we have a different ways on how we can pass the stuff which are part of the URI and more particularly the leading or ending "/" :

baseURL: "http://www.slackers.com" //no ending slash 
endpoint: "/security" //we have to start with a slash

But we can also do it the otherr way around :

baseURL: "http://www.slackers.com/" //ending slash 
endpoint: "security" //no starting slash

Both are valid because our library (at least JavaScript) don't do any manipulation for baseURL and endpoint.

But if you take the parameter id on the read function, this one must not have a leading "/" because it's added by the library:

id: "team1" //works
id: "/team" //fails

Until now id was the last part of the URI but since we are planning to add nested resources, id won't be necessarily the last fragment. For example, we could have a new parameter called resource to be appended at the end :

baseURL = "http://www.slackers.com/" //ending slash 
endpoint: "security" // no starting slash
id: "5" // handled by lib
resource: "/crypto" //leading slash needed

As the spirit of Pipes (at least for REST) is to offer an abstraction around the Ajax and URL handling plumbing code, I think we should have a convention for passing URI fragments that is the same for all. My suggestion is to do the same as for id : no leading / or ending /.

If the user passes the a leading or ending /, the library will removed it because it will be added. This way we are safe.

Remarks ? Questions ?

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