Overview
To create a basic rest api you can implement any of the entity interfaces required for your api
Use the available interfaces to create a CRUD api for your entity
Example classes
abstract class APIRoute<E: Any> (
val parent: API = API() // (1)!
): CreateEntity<T>, UpdateEntity<T> {
abstract val repo: BaseRepository
// write code to base
}
@Resource("user")
class UserRoute: APIRoute<User>() {
val repo: UserRepository = UserRepository()
//...
}
- You can create a parent argument to define the base path for your API.
Define route
fun Application.module() {
install(Resources)
createRoutes<UserRoute, User>() // (1)!
}
- Also handles some basic functionality with serialization using kotlinx
URL Pattern
createRoutes
creates the following URL patterns for your entity based on the interfaces implemented.
Any prefix url can be added by adding a parent to your route!
URL | Method | Interface |
---|---|---|
{entity}/ |
GET | GetEntity |
POST | CreateEntity |
|
{entity}/{pk}/ | GET | GetEntity |
PUT | UpdateEntity | |
DELETE | DeleteEntity | |
{entity}/{action}/ | POST | EntityAction |