Answer the question
In order to leave comments, you need to log in
What about camelCase on the front and snake_case on the backend?
The question is, on the front we use camelCase in everything. But when data arrives from the backend in the form:
{ first_name: 'First', last_name: 'Last', is_admin: false, is_premium: true, avatar_url: 'some-url' }
Answer the question
In order to leave comments, you need to log in
If the backender is of a very high level, that is, it can beautifully and optimally design methods and data for the needs of client applications, clearly document it (swagger) and cover its methods with tests, then usually there are no such problems.
Otherwise, control everything that comes from the backend, make static mappers, adjusting to the backend is not an option, all sorts of linters will start to swear, you will start to get confused in poorly named variables, persuade backenders to send data in the right format, spend more time, the third option is acceptable, the backend often sends, not only in the right format, but also a lot of things that are not needed for the front.
For example: backend sends (this is a common situation, for example, it is stored in the database, and different clients (web, ios, android) have their own encoding rules, but they can use the same backend)
{
ID '2342',
stu_cfg: 'werwer'
pfu_num: '1231'
sys_created: '2000-12-10'
register_date: '06 Mar 2017 21:22:23 Z'
}
interface SomeEntity {
id: string,
status: string,
created: Date
registered: Date
}
class MyMapper {
static someEntityToClient(data): SomeEntity {
const someEntity: SomeEntity = {
id = data['ID'],
status = data['stu_cfg'],
created = moment(data['sys_created']).toDate
registered = moment(data['register_date']).toDate
}
return someEntity;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question