resturlurl-design

What is the best practice in RESTful URL?


I want to design a RESTful URL to select designers that have a specific category.

This is my domain relationship:

designer <-> product <-> category

I thought of two ways:

I want to know what is better.


Solution

  • I primarily intended to write a comment, but it's the way too long so I've written an answer instead.

    I want to design a RESTful URL to select designers that have a specific category.

    There's no such thing as RESTful URL: It's a wrong technical term that seems to come from the idea that URIs should be meaningful and express semantics to the client in REST applications. It's a misconception.

    Roy T. Fielding defined the REST architectural style in the chapter 5 of his dissertation. This document defines a set of constraints that must be followed by applications that follow such architecture and it doesn't enforce any URI design.

    When designing REST APIs, however, it's a common approach to use nouns instead of verbs in the URI: REST is meant to be designed around resources, which are manipulated using representations according to the semantics of the HTTP methods. While user-friendly URIs might be desirable, they are by no means mandatory from the REST architectural style perspective. The URI itself won't make the API more or less RESTful.

    Having said that, if such thing as RESTful URL exists, what do non-RESTful URLs are like?


    I want to know what is better.

    Answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. What you'll read from this point is my personal opinion.

    Assuming that you intend to use use URIs that are user-friendly, resource-oriented and easy to remember, I would use /designers?categoryId={id}: it indicates that a collection of designer resources is mapped it to /designers and such collection can be filtered using the categoryId query parameter.