Service specification
First we need to specify the exact scope and API of our service. We’ll design a service with a minimal API to keep things simple. It shall fulfil the following requirements.
The service shall provide HTTP API endpoints for:
- the creation of a product data type identified by a unique id
- adding translations for a product name by language code and unique id
- returning the existing translations for a product
- returning a list of all existing products with their translations
Data model
We will keep the model very simple to avoid going overboard with the implementation.
- A language code shall be defined by the ISO 639-1 (e.g. a two letter code).
- A translation shall contain a language code and a product name (non-empty string).
- A product shall contain a unique id (UUID version 4) and a list of translations.
Database
The data will be stored in a relational database (RDBMS). Therefore we need to define the tables and relations within the database.
The products table
The table products must contain only the unique id which is also the primary key.
The names table
The table names must contain a column for the product id, one for the language code and one for the name. Its primary key is the combination of the product id and the language code. All columns must not be null. The relation to the products is realised by a foreign key constraint to the products table via the product id.
HTTP API
The HTTP API shall provide the following endpoints on the given paths:
| Path | HTTP method | Function |
|---|---|---|
/products |
POST | Create a product. |
/products |
GET | Get all products and translations. |
/product/{UUID} |
PUT | Add translations. |
/product/{UUID} |
GET | Get all translations for the product. |
The data shall be encoded in JSON using the following specification:
1 {
2 "lang": "ISO-639-1 Code",
3 "name": "A non empty string."
4 }
1 {
2 "id": "The-UUID-of-the-product",
3 "names": [
4 // A list of translations.
5 ]
6 }
This should be enough to get us started.