REST API Questions

I'm creating a service with RESTful APIs which will be responsible for serving Oracle transaction logs. The service will provide GET and DELETE APIs to fetch/delete transaction logs in a given time range.

For creating APIs, I have 2 options:

GET: /table/{tableName}/logs?startTime=<>&endTime=<>


GET: /logs/table/{tableName}?startTime=<>&endTime=<>

similar for delete use case.

Which one of these would you pick and why?

3 answers

  • answered 2017-08-16 19:32 zmbq

    Correct REST design principles make me tired. There are a lot of very emotional arguments about these. So I don't know what is correct in terms of REST based design, but I do know what I would choose:

    I would go with /logs/table/... if you have another log-related resource other than tables. If not, I would go with /table.

    By the way, why table and not log? The resource is a transaction log, isn't it?

  • answered 2017-08-16 19:32 JoshKopen

    To be fair, REST is fairly open to interpretation as far as what is "correct" but I would probably go with the first option. I think that the URL should be designed in a somewhat logical order. First, you are looking at a table, then looking at a specific table, then looking at that table's logs. This makes more logical sense. Secondly, when you do the query at the end of the URL, the query is really on the logs so having the query as close to the word logs as possible makes the most logical sense.

  • answered 2017-08-16 19:32 Evert

    REST does not say anything about the correct structure of your urls. In fact, it suggests that urls should be discovered and irrelevant to clients. It's considered a best practice to create a logical URL structure, but this is only intended useful for humans and not for REST clients.

    Which is better is completely subjective but either is correct in terms of REST based design.