简体   繁体   中英

REST API URI Design

I need to develop a REST API and I have doubts about the URI design.

Scenario:

1 - I'm developing one REST interface to a set of services.

2 - each service is divided from the logical point of view in several parts ( not resources).

3 – each resource can be accessed in two ways "A" and "B"

What is the most appropriate URI design:

/service1/part1/resource?{A|B}

/service1,part1,resource?{A|B}

虽然这两种URL结构都可以使用,但您列出的/ service1 / part1 / resource?{A | B}中的选择更为典型,并且具有使用常见REST API消耗工具的机会最高,开发人员可以直观地理解等等。正斜杠的含义实际上是在URI标准(我认为是RFC 1630)中定义的,相对URI仅适用于正斜杠。

This one is better:

/service1/part1/resource?{A|B}

as it emphasizes hierarchy (thanks to slashes).

Also "the ways resources are accessed" are usually pronounced using HTTP verbs (such as GET, POST, PUT, DELETE, HEAD etc.). If this is what you meant by "ways", you should definitely stick to HTTP verbs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM