Skip to content

ThrowPeople/SimpleContext

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

It's just a project like a toy, it's not very well implementation.

SimpleContext

A Simple Web Framework written in kotlin

Usage

val simpleContext: SimpleContext = SimpleContext.simpleContext()
val simpleRouter = SimpleRouter.build()

simpleRouter.get("/ping") { ctx ->
    ctx.end()
}
simpleContext
    .createHttpServer()
    .route(simpleRouter)
    .listen("127.0.0.1", 8080)
    .start()

Controller

class ExamplePageController : BaseController {
    private val greetingService: ExampleService = ExampleServiceImpl()
    override fun register(router: SimpleRouter) {
        router.get("/getCalender", ::getCalender)
    }

    private fun getCalender(ctx: HttpGetContext) {
        val resultMap = HashMap<String, Any>()

        val dateTime = greetingService.getCalender()
        ctx.getHeader("")

        resultMap["time"] = dateTime
        ctx.end(resultMap)
    }
}

Service

interface ExampleService {
    fun getCalender(): String
}

class ExampleServiceImpl : ExampleService {
    private val exampleMapper = ExampleMapper()

    override fun getCalender(): String {
        return exampleMapper.timeString
    }
}

Mapper

class ExampleMapper {
    // Mock Mapper
    var timeString: String = Calendar.getInstance().toString()
}

About

🌟 Web Framework based on Java Socket

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published