MVC: RESTful routing with nested URLs when entities are not nested

It's really hard for me to spend time with the RESTful paradigm + sub-URLs. I asked a question that will lead me to where I am here now . My domain is something like this: there are schools, school courses, and school teachers. Now schools, courses and teachers are not "nested" entities in the sense that you can refer to any of them with one identifier. The site is a collection of "microsites" for each school, which shows all courses and teachers. A course or teacher can exist in only one school.

Say we have url like / schools / 1 / courses / 10. Course 10 of school 1. This works great. Let's say that the user manually changes 10 to 11, which happens, but this is the course of school 2. Now, when this leads to confusion, my site still β€œthinks” that the user is in school 1, but shows course 3 as part of it.

Do I have to perform detailed actions, parametric for both the Identifier requested and the β€œparent” object (in this case, the school) in which it participates? To choose from the repositories not only an identifier, but also a school restriction?

Or is there a better way to do this?

+3
source share
3 answers

; 11, URI//1//11 . URI , HTTP 404 URI.

( , ). URI . ////.

. , , , , . /// , . XML-, :

<courses>
    <course uri="/schools/hogwarts/courses/defense+against+the+dark+arts">Defense against the dark arts</course>
    <course uri="/schools/hogwarts/courses/potions">Potions</course>
</courses>
+1

Id "" ( ), ? ?

.

Or is there any better way to do this?

, .

+1

catch-all, url.

-1
source

Source: https://habr.com/ru/post/1724499/


All Articles