7
7
700ghz2018-12-21 11:47:06
API
700ghz, 2018-12-21 11:47:06

API POST field - ID vs Name?

Building an API, endpoint: POST BOOK
There is a BOOK_TYPES table : 1 - 'science', 2 - 'erotic', 42 - 'novel'
(there is a GET ALL_BOOK_TYPES endpoint)
Which request body is more convenient for frontend development:
POST BOOK:

{
title: ‘Idiot’,
bookType: 42,
}

OR
POST BOOK:
{
title: ‘Idiot’,
bookType: ‘novel’,
}

Thank you in advance! :)
PS which request body is more convenient for a frontend developer (client): bookType: 42 or bookType: 'novel'? :)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey, 2018-12-21
@700ghz

Do not care, the developer will still refer to the property of its object when assembling the request.
And id is better here, as it unifies the code ..

K
Konstantin Nagibovich, 2018-12-21
@nki

Add one more field to the response and get the name, type name and type ID.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question