Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Benefits of RESTful URL

Tags:

rest

What are the benefits of

 http://www.example.com/app/servlet/cat1/cat2/item 

URL

over

 http://www.example.com/app/servlet?catid=12345

URL

Could there be any problems if we use first URL because initially we were using the first URL and change to second URL. This is in context of large constantly changing content on website. Here categories can be infinite in number.

like image 366
Harry Avatar asked Jun 23 '12 16:06

Harry


People also ask

What is the purpose of URL in RESTful web services?

RESTful Web Services - Addressing Purpose of an URI is to locate a resource(s) on the server hosting the web service. Another important attribute of a request is VERB which identifies the operation to be performed on the resource.

What's the major benefit of REST API?

One of the key advantages of REST APIs is that they provide a great deal of flexibility. Data is not tied to resources or methods, so REST can handle multiple types of calls, return different data formats and even change structurally with the correct implementation of hypermedia.


2 Answers

In relation to a RESTful application, you should not care about the URL template. The "better" one is the one that is easier for the application to generate.

In relation to indexing and SEO, sorry, but it is unlikely that the search engines are going to understand your hypermedia API to be able to index it.

To get a better understanding in regards to the URLs, have a look at:

  • Is That REST API Really RPC? Roy Fielding Seems to Think So
  • Richardson Maturity Model
like image 92
Tom Howard Avatar answered Nov 07 '22 06:11

Tom Howard


One difference is that the second URL doesn't name the categories, so the client code and indeed human users need to look up some category name to number mapping page first, store those mappings, use them all the time, and refresh the list when previously unknown categories are encountered etc.. Given the first URL you necessarily know the categories even if the item page doesn't mention them (but the site may still need a list of categories somewhere anyway).

Another difference is that the first format encodes two levels of categorisation, whereas the second hides the number of levels. That might make things easier or harder depending on how variable you want the depth to be (now or later) and whether someone inappropriately couples code to 2-level depth (for example, by parsing the URLs with a regexp capturing the categories using two subgroups). Of course, the same problem could exist if they couple themselves to the current depth of categories listed in a id->category-path mapping page anyway....

like image 30
Tony Delroy Avatar answered Nov 07 '22 06:11

Tony Delroy