Skip to content

hiteshchopra11/ktor-api

Repository files navigation

KtorAPI

KtorAPI is a project which demonstrates the power of Kotlin's Ktor in developing powerful REST APIs with all basic as well as advanced features.

Ktor version -: 2.1.3

Architecture

Ktor Controller (http) -> Service (business) -> Repository (data)

Features

  1. Create Notes
  2. Update Notes
  3. Fetch Notes
  4. Delete Notes
  5. JWT Authentication
  6. Ktorm ORM for DB
  7. Dependency Injection using Koin
  8. Pagination
  9. Sorting results using query parameters
  10. Middlewares/Plugins for Logging

Coming soon -:

  1. Unit Testing
  2. Searching
  3. Exporting data in excel format
  4. Exporting data in csv format

Installation

Use IntelliJ IDEA, community or enterprise edition to open the project and follow these steps to run the Application.

Notes -: Customise the application.conf file which is not included with the project for security reasons. Specify the ktor object in the application.conf file and fill your own secret, audience, issuer, realm to configure the JWT authenticaton settings. Similarly,specify your port and host inside the application.conf file in which you want to run the server.

Start the MySQL server to use the notes API.

Usage

Notes API

  1. Create a new note
POST http://0.0.0.0:3536/notes
Content-Type: application/json

{
  "note": "your-note",
}
  1. Fetch all notes
GET http://0.0.0.0:3536/notes
  1. Fetch a particular note
GET http://0.0.0.0:3536/notes/{id}
  1. Delete a particular note
DELETE http://0.0.0.0:3536/notes/{id}
  1. Update a particular note
PUT http://0.0.0.0:3536/notes/{id}
  1. Fetch paginated notes
GET http://0.0.0.0:3536/paginatedNotes?size=5&page=1
  1. Fetch sorted notes
GET http://0.0.0.0:3536/notes?sort=asc

JWT Authentication

  1. Generate an Auth Token
POST http://0.0.0.0:3536/generate-token
Content-Type: application/json

{
  "username": "username",
  "password": "password"
}
  1. Test the Auth token
GET http://0.0.0.0:3536/test
Authorization: Bearer {{auth_token}}

About

Rest APIs performing CRUD Operations using Ktor

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages