W
W
WebDev2020-09-04 13:05:16
RESTful API
WebDev, 2020-09-04 13:05:16

Long addresses for API - is it normal?

I have a nested entity structure: a page is created, pictures are created for the page, links are created for each picture. That is, you need crud for the page, picture and link. I do like this:

Route::post('pages/create',  '[email protected]');
Route::post('pages/{page}/delete', '[email protected]');
Route::post('pages/{page}/images/create',  '[email protected]');
Route::post('pages/{page}/images/{image}/update',  '[email protected]');
Route::post('pages/{page}/images/{image}/delete',  '[email protected]');
Route::post('pages/{page}/images/{image}/links/create', '[email protected]');
Route::post('pages/{page}/images/{image}/links/{link}/update',  '[email protected]');
Route::post('pages/{page}/images/{image}/links/{link}/delete',  '[email protected]');

I'm wondering if this is correct? It would be possible to make them shorter (not nested), but with this approach it is immediately clear that the picture is from the page.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
d-sem, 2020-09-04
@kirill-93

Can be shortened by using HTTP methods according to their semantics.
POST new entity creation
PATCH, UPDATE change
DELETE delete

D
Dr. Bacon, 2020-09-04
@bacon

It would be possible to make them shorter (not nested), but with this approach it is immediately clear that the picture is from the page.
And why is it necessary to make it clear, for what purpose?
So how unique are image and link values? If they are unique, then taking into account PUT, DELETE and other
'pages/'
'pages/{page}/'
'pages/{page}/images/'
'images/{image}/'
'images/{image}/links/'
'links/{link}/'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question