» Node.js: Building Event-Driven Microservices with Kafka » 2. Producer: Web Service » 2.3 Data Models
Data Models
Data models represent the structure of the data that the API deals with. These models define the shape of the data entities exchanged between the client and the server.
For example, in this books management microservices project, a Book
model can be defined:
Create src/domain/model/book.ts:
Folder structures like
domain/model/...
is using 4 Layers Architecture Pattern, read more here.
// Book represents the structure of a book
export interface Book {
id: number;
title: string;
author: string;
published_at: string;
description: string;
created_at: Date;
}
Create src/domain/model/index.ts:
export { Book } from "./book";
The index.ts in a sub-folder helps to re-export symbols within that folder.
Loading...
> code result goes here