This project is a lightweight HTTP server library built using Kotlin Coroutines. It allows you to define RESTful routes easily and handle JSON-based HTTP requests/responses in a clean, coroutine-first style.
- Lightweight and fast server
- Clean routing DSL
- JSON request/response handling
- Coroutine-based request processing
- Dynamic routes and path parameters
- Easy to extend and customize
- Kotlin (JVM)
- Coroutines
- kotlinx.serialization (for JSON handling)
- Java’s built-in
HttpServer
Follow these steps to get the server up and running:
git clone https://github.com/pankaj046/RestApiServer.git
cd RestApiServer
./gradlew build
./gradlew run
URL: /api
Method: GET
Response:
{
"status": "healthy",
"timestamp": 1715018245000
}
URL: /api
Method: POST
Request Body:
{
"email": "[email protected]",
"password": "password123"
}
Response:
{
"success": true,
"message": "Login successful",
"user": {
"email": "[email protected]"
}
}
URL: /api/dynamic
Method: POST
Request Body: Any JSON object
Response:
{
"received": { "key": "value" },
"message": "Data received successfully"
}
URL: /api/users/{id}
Method: GET
URL: /api/users/{id}
Method: PUT
Request Body:
{
"name": "John Doe",
"email": "[email protected]"
}
URL: /api/users/{id}
Method: DELETE
You can define your own routes using the route
, get
, post
, put
, and delete
functions:
route("/myroute") {
get { ctx ->
ctx.respond(200, mapOf("message" to "Hello from /myroute"))
}
}
curl -X POST http://localhost:8080/api -H "Content-Type: application/json" \
-d '{"email": "[email protected]", "password": "123456"}'
Developed with ❤️ by Pankaj
This project is licensed under the MIT License.