0

I'm creating a simple API which works with geographical data.

Some URLs look very simple like:

GET /towns/{id} 

or

GET /towns 

Now I want to get a town by alias, should I use this kind of URL?

GET /towns/alias/{alias} 

What if I also want to get a list of towns located near certain town?

GET /towns/closest/{id}/radius/{radius} 

I understand that my URLs can be any I want. What is a canonical way to do it?

2 Answers 2

1

I understand that my URLs can be any I want. What is a canonical way to do it?

There isn't really a "canonical way" to design URLs, any more than there is a canonical way to name variables -- there are only local spelling conventions.

RFC 3986 distinguishes between hierarchical and non-hierarchical data:

The path component contains data, usually organized in hierarchical form, that, along with data in the non-hierarchical query component (Section 3.4), serves to identify a resource within the scope of the URI's scheme and naming authority (if any)

The effect of using hierarchical data is that you can take advantage of dot-segments to compute one URI from another.

For example

/town/alias/{alias} /alias/{alias} 

Both of these spellings are "fine", but /town/alias gives us the option of using dot segments to specify an identifier under /town

/town/alias/abc + ../123 => /town/alias/../123 => /town/123 

That can be handy when it allows you to re-use a representation for multiple resources in your hierarchy.

Sign up to request clarification or add additional context in comments.

Comments

0

Yes it can possible through the URL routing.You can send any number of parameter through url.

Can you please confirm the technology you used?

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.