Creation API
Once configured a module for a model, POST API will be available via http requests.
For instance, take this model as an example
data class Game(
val name: String,
val players: Int?): Identifiable()
Configure the module it’s simply done by adding inside startKDone DSL
module<Game>("games")
To add a Game document in MongoDB use an http POST request.
Endpoint
games
Method
POST
Body
{
"name": "CTR",
"players": 7,
"_id": "5e183d4333e63f6731d70b47"
}
Result
{
"name": "Horizon: Zero Dawn",
"players": 1,
"_id": "5e1837939781db4d055afafb"
}
The model has as attributes
- name a nonoptional
String
- players an optional
Ìnt
This means that in the body passed to the POST request name
is mandatory and players
is optional.
This is permitted
{
"name":"CTR"
}
This will return a 400 Bad request
error
{
"players":7
}