ktor-api-client is a powerful open-source Kotlin project that demonstrates how to build modern, scalable RESTful APIs and real-time chat applications using the Ktor framework.
This project provides a complete backend solution supporting both Firebase Firestore and MySQL for data storage. It features a robust real-time chat system powered by WebSockets, alongside essential authentication APIs (login, register, and user profile management) with support for local image uploads.
- ✅ Build production-ready REST APIs in Kotlin
- 🔥 Integrates with Firebase Firestore and MySQL
- 🧪 Fully working Ktor authentication API example
- 📁 User image uploads stored locally in the
/uploadsdirectory - 💻 Perfect for backend developers learning Ktor + Kotlin + Firestore + MySQL
Authenticate user credentials.
Request Body:
{
"email": "user@example.com",
"password": "password123"
}Register a new user.
Request Body (multipart/form-data):
name: Stringemail: Stringpassword: StringuserImage: File
Get a list of all registered users.
Real-time chat using MySQL.
Connect via WebSocket to send and receive messages.
Follow these steps to get your Ktor + MySQL + Firebase backend up and running in minutes.
git clone https://github.com/KishanViramgama/ktor-api-client.git
cd ktor-api-client- Install MySQL Server (v8.0 or later).
- Open MySQL Workbench or your preferred SQL terminal.
- Run the following SQL command to create the database:
CREATE DATABASE login_register;
- Configure Credentials:
- Open
src/main/resources/application.conf. - Update the
userandpasswordfields under thestorageblock to match your local MySQL settings. - Default settings in this project:
user:rootpassword:MySql@2026
- Open
- Go to the Firebase Console.
- Create a new project or select an existing one.
- Navigate to Project Settings > Service accounts.
- Click Generate new private key. A
.jsonfile will be downloaded. - Add the file: Copy this JSON file into the
src/main/resources/directory. - Link the file: Open
src/main/kotlin/Application.kt, find theinitFirebase()function, and update the filename to match your downloaded JSON:val serviceAccount = Application::class.java.getResourceAsStream("/your-firebase-file.json")
To allow mobile apps or other devices to connect, you must use your machine's Local IP Address.
- Find your IP:
- Windows: Run
ipconfigin CMD. - Mac/Linux: Run
ifconfigorhostname -I.
- Windows: Run
- Update IP in Code:
- Open
src/main/kotlin/base/Base.kt. - Update
IP_ADDRESSto your current local IP (e.g.,192.168.1.5).
const val IP_ADDRESS = "your.local.ip.here"
- Open
- Verify Port: The default port is
8080. Ensure this port is open on your firewall.
Open the project in Android Studio or IntelliJ IDEA and run the ApplicationKt file, or use the terminal:
./gradlew runOnce started, you will see:
✅ Connected to MySQL Database✅ Firebase Initialized[main] INFO ktor.application - Responding at http://0.0.0.0:8080
Since Postman (standard) doesn't always handle Ktor WebSockets perfectly, you can use the Postman WebSocket Request or a tool like wscat:
- Postman: Click
New>WebSocket Request. - URL:
ws://192.168.5.240:8080/chat/user1/user2(for Firebase) orws://192.168.5.240:8080/mysql/chat/user1/user2(for MySQL). - Communication: Once connected, send a JSON message:
{ "text": "Hello!", "receiverId": "user2" }
If you are starting a new Ktor project and want to match this setup, use the Ktor Project Generator with these selections:
- Project Type: Kotlin
- Configuration Engine: Netty
- Build System: Gradle Kotlin DSL
- Plugins to Include:
Routing: For handling API endpoints.Content Negotiation+kotlinx.serialization: For JSON support.WebSockets: For real-time chat functionality.Static Content: To serve uploaded images from the/uploadsfolder.Exposed: For MySQL ORM integration.
- 🔐 Learn Ktor authentication
- 🔄 REST API integration with Firebase + MySQL
- 💬 Implement Real-time Chat using WebSockets
- 🧰 Use as boilerplate for Kotlin backend projects
- 🧪 Practice handling file uploads and image storage in Ktor
ktor,kotlin,kotlin ktor,ktor rest api,ktor firebase mysql,authentication api,kotlin backend,ktor client server,kotlin rest api,ktor image upload,kotlin api example,ktor websocket chat,kotlin realtime chat,ktor mysql chat
Test all APIs easily using the included Postman collection.
📥 Download Postman Collection
Looking for a mobile application that demonstrates user login and registration using the same Ktor API provided in this project? Check out the companion Android demo app:
🔗 Android Demo App (Login & Register):
https://github.com/KishanViramgama/LoginRegister
This Android project is fully integrated with this API and showcases:
- ✅ User registration flow
- 🔐 User login handling
- 🔗 Ktor client API integration
- 🎨 Jetpack Compose UI (if applicable)
Clone and run the app on your emulator or device to experience the complete authentication flow in action.
Pull requests and issues are welcome! Feel free to fork the project and enhance it.
Follow me on GitHub to stay updated with Kotlin, Ktor, and backend projects! 🌟
If you like this library and want to support my work, consider buying me a coffee.