Why use "?" instead of ":" in URL? - url

We can use
'PATCH /companies/:id' : 'CompanyController.find'
to update data.
One suggested me that I can use the alternative way:
'PATCH /companies/find?key=Value'
But I do not know what it works. Please explain me why we prefer ? mark than : mark in search path.

You can use either or. The biggest reason most people chose one or the other is just how they want to present the URL to the user.
Using a path variable (:) can symbolize you're accessing a defined resource, like a user ID, where as an argument (?) can symbolize you're are dynamically changing/searching something within a defined resource, like a token or search term.
From what I can tell that's the general practice I see:
example.com/user/:username
versus
example.com/user/?search="foo"

http://en.wikipedia.org/wiki/URL
If we are firing GET request, ? symbol is used to let the server know the url parameter variables starts from there. And this is commonly used. I didn't used : symbol instead of ?

You are probably messing the things up:
According to your example, :id indicates a variable that must me replaced by an actual value in some frameworks such as Express. See the documentation for details.
And ? indicates the beginning of the query string component according to the RFC 3986.

It's a rule to design rest api
you can find 'how to design a rest api'
Assuming below code is Sails.js
'PATCH /companies/:id' : 'CompanyController.find'
It will makes REST API that be mapped onto 'CompanyController.find' by using PathParam. Like this
www.example.com/companies/100
Second one will makes REST API by using QueryParam.
It also be mapped onto 'CompanyController.find'
/companies/find?key=Value
But the API format is different. Like this
www.example.com/companies/find?key=100
PathParam or QueryParam is fine to make REST API.
If the Key is primary for company entity,
I think PathParam is more proper than QueryParam.

Related

How can i trim URLs to root domain? i'm using notepad++

I have a list of domain name with parameters
http://www.anandinfra.net/project.php?id=2
http://artlinkinteriors.com/page.php?id=1
http://www.rabinmukherjeecollege.in/notice_details.php?id=1
I need to find other parts with domain and I have to replace those parts.
Finally my result should look as follows. Expected result:
http://www.anandinfra.net/
http://artlinkinteriors.com/
http://www.rabinmukherjeecollege.in/
How can I attain this result?
Hi you can create a CNAME in the DNS setting with the
http://www.anandinfra.net/project.php?id=2 pointing to http://www.anandinfra.net/
and same for the rest
In whatever programming language you use (which you don't disclose), find the relevant library handling URLs and use it to mutate them. DO NOT attempt to do that by string manipulation.

Using Breeze query not invoking action

I am developing single page application using HotTowel.
My question is that, When I am writing a Breeze query with string parameter whose length is greater than 1600 characters then action is not invoking.
Please let me know the reason.
Thanks in advance.
as stated in:
What is the maximum length of a URL in different browsers?
there is a limit for the length of urls
check parametrized queries as a possible workaround:
How to properly send action parameter along with query in BreezeJs
The answer from #fops is correct. Using .withParameters, you may be able to create some methods on your server that allow you to use some shorthand on the client instead of very large queries.
If your queries are really big, and even .withParameters blows up your URL, you may need to use POST instead of GET.
Breeze doesn't support POST for queries directly, but there's an (unsupported) add-on in Breeze Labs called breeze.ajaxpost.js that will let you use POST for .withParameters queries.

How can I retrieve an id from the url in Coldfusion?

I'm updating a site and am struggling to find a way to get an id from the URL. For example I have this:
http://some.html/search.cfm?id=9900000000301
How do I get the id value "9900000000301" from the URL in Coldfusion8?
I have tried url.id plus all sorts of *cgi.query_string* variations, but the number is still out of reach :-(
Thanks for help!
EDIT:
If I dump the URL struct, I'm getting this:
catch - struct
TYPE: default
VALUE: search
Which is not saying much to me.
The url.id should work just fine.
Url.Id will work - with one exception.
If you have created a variable called Url, it is possible (in Adobe CF) to "hide" the Url scope, and thus not be able to access it.
For example, if you have a function with an argument called url, referring to url inside that function will refer to Arguments.Url, not the Url scope. If this is the case, you need to rename the argument to be able to access the proper Url scope.
(Alternatively, switch to a better CFML engine where scope names always takes precedence over unscoped variables, and thus scopes cannot be hidden.)
Depending on how you are looking to use the data, here are two examples. The first checks to see if it was defined and the second sets a variable to the value.
<cfif isDefined("URL.id")>
<cset myVariable = URL.id>
</cfif>
Hope this helps!

is it bad form to have the colon in db and in the URL?

I am designing my namespace such that the id i am storing in the DB is
id -> "e:t:222"
where "e" represents the Event class, "t" represents the type
i am also expecting to use this id in my urls
url -> /events/t:222
Is there anything wrong with doing this?
Is there anything wrong with doing this?
Yes: The colon is a reserved character in URLs that has a special meaning, namely specifying the server port, in a URL.
Using it in other places in the URL is a bad idea.
You would need to URLEncode the colon in order to use it.
There is nothing wrong with doing this, you'll simply need to encode the URL properly. Most libraries with do this automatically for you.
In general though, if you care about your data you shouldn't let the application drive the data or database design. Exceptions to this are application centric databases that have no life outside of a single application nor do you expect to use the data anywhere else. In this case, you may want to stick with schemas and idioms that work best with your application.

Restlet - Access elements of the request URL

I'm unsure what the proper way is to access parts of the requested URL.
In this case, I want to get the requested path without the query variables. This is the only way I found to do it:
String path = getRequest().getResourceRef().getHostIdentifier() +
getRequest().getResourceRef().getPath();
The result would be the bold part of this url: https://stackoverflow.com/questions/ask?query=value
I also found about 6 different ways to get the server name (http://stackoverflow.com) but I'm worried that some of them would fail in certain cases that I am unaware of (why would there be 6 different ways to do one thing):
getRequest().getHostRef().getHostIdentifier();
getRequest().getHostRef().getIdentifier();
getRequest().getRootRef().getHostIdentifier();
getRequest().getRootRef().getIdentifier();
getRequest().getResourceRef().getHostIdentifier();
And this seems to get the complete URL with query parameters:
getRequest().getResourceRef().getIdentifier();
Any further explanation would be much appreciated.
If you're in a UniformResource (or subclass) I think you might be looking for the method getReference(), which returns the URI reference. There are a number of other convenience methods in that class you might be interested in so you don't have to go through the request. See UniformResource (Restlet 2.0).

Resources