/BorutoServerNew

Back-end server for Boruto app

Primary LanguageKotlin

Boruto API

an API for Boruto anime heroes using Ktor and Koin

Plugins

Many applications require common functionality that is out of scope of the application logic. This could be things like serialization and content encoding, compression, headers, cookie support, etc. All of these are provided in Ktor by means of what we call Plugins.

Plugins :

  • Routing : Routing is the core Ktor plugin for handling incoming requests in a server application. When the client makes a request to a specific URL (for example, /hello), the routing mechanism allows us to define how we want this request to be served.

  • Content negotiation and serialization : The ContentNegotiation plugin serves two primary purposes:

    • Negotiating media types between the client and server. For this, it uses the "Accept" and "Content-Type" headers.

    • Serializing/deserializing the content in a specific format. Ktor supports the following formats out-of-the-box: JSON, XML, and CBOR.

  • Default headers : The DefaultHeaders plugin adds the standard Server and Date headers into each response. Moreover, you can provide additional default headers and override the Server header.

  • Call logging : Ktor provides the capability to log application events using the SLF4J library. The CallLogging plugin allows you to log incoming client requests.

  • Status pages : The StatusPages plugin allows Ktor applications to respond appropriately to any failure state based on a thrown exception or status code.

Dependency Injection

What is dependency injection?

Dependency injection (DI) is a technique widely used in programming and well suited to Android development. By following the principles of DI, you lay the groundwork for good app architecture.

Implementing dependency injection provides you with the following advantages:

  • Reusability of code
  • Ease of refactoring
  • Ease of testing

What is Koin?

Koin is a pragmatic and lightweight dependency injection framework for Kotlin developers.

Koin is a DSL, a light container and a pragmatic API

Koin for Ktor

Additional Resources:

Testing

Ktor

Ktor Testing Documentation

Ktor provides a special testing engine that doesn't create a web server, doesn't bind to sockets, and doesn't make any real HTTP requests. Instead, it hooks directly into internal mechanisms and processes an application call directly. This results in quicker tests execution compared to running a complete web server for testing.

Koin

Koin Testing Documentation

By tagging your class KoinTest, your class become a KoinComponent and bring you:

  • by inject() & get() - function to retrieve your instances from Koin
  • checkModules - help you check your configuration
  • declareMock & declare - to declare a mock or a new definition in the current context