M
M
Mikhail Ivanov2017-08-06 17:35:05
API
Mikhail Ivanov, 2017-08-06 17:35:05

Access to REST API resources?

For example, there is an application that stores information about transport (type of transport, its characteristics) and about enterprises that produce a particular transport.
In the database, the transport is in the Transport table, each transport has a type.
In the API, it is necessary to provide access to the transport by its type, for example. like this:
/motorcycles/
/autos/
/bicycles/
etc.
The API should be able to get vehicles produced by a certain enterprise.
For example:
/manufacturers/transports/
Question: what is the best way to return information about the transport that the company produces? If only Id is returned, the API user will not understand which endpoint to use.
UPD: Data about enterprises and transport are in different databases. The application is divided into modules and the module that works with enterprises does not know anything about the transport, except for identifiers.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel Volintsev, 2017-08-06
@copist

You in vain type of transport "sewn up" in URL, from it and confusion.
The classic REST API operates on entities. You have the entities "manufacturer", "vehicle types", "manufacturer's vehicles", "manufacturer's vehicle types" and "vehicle"
GET /api/transport-types list of vehicle types
GET /api/transport-type/[ id] one specific vehicle type
GET /api/manufacturers list of manufacturers
GET /api/manufacturer/[id] manufacturer description (name, address)
GET /api/manufacturer/[id]/transport-types list of manufacturer vehicle types
GET / api/manufacturer/[id]/transport-type/[id] manufacturer's vehicle type description
GET /api/manufacturer/[id]/transports list of manufacturer's vehicles
GET /api/manufacturer/[id]/transport/[id] description of one manufacturer's vehicle
GET /api/manufacturer/[id]/transport/[id] description of one vehicle manufacturer
The level of detail of the answer is up to you. You can make the lists return only the ID, and receive the rest of the information with additional requests. And you can make it so that the list will immediately contain a lot of basic and additional information.
This is approximate, just for information.
More separately for adding, updating, deleting
You can move away from the concept of REST and take RPC. Then, in response, you can return as much information as you like in any form.
GET /api/get-transport-type-of-manufacturer?manufacturer_id=[id]&transport-type_id=[id] return manufacturer's vehicle type description

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question