Coaching this? Find the source here.
This template app was built using:
- Kotlin
- http4k for the HTTP webserver and routing
- ktorm to integrate with the PostgreSQL database
- Handlebars for views templating
- JUnit and hamkrest for testing
- Users can sign up, sign in and log out
- The page to create a new post is implemented, but submitting it is not yet done
- Users have to be signed in to create posts
You'll need to IntelliJ editor. If not installed already, head to https://www.jetbrains.com/idea/download/#section=mac and download the Community Edition.
Once installed, open the project directory into IntelliJ.
This project uses PostgreSQL as a database. You'll need to install this first.
Create two PostgreSQL databases acebook_kotlin
and acebook_kotlin_test
.
In both databases, import the SQL dump in the file resources/database.sql
.
Run the configuration "Acebook (Dev)" in the top-left corner of IntelliJ.
This should run the server on port 9000 (you can leave it running in the background).
Head to http://localhost:9000 to browse the app.
Run the configuration "Acebook (Test)" in the top-left corner of IntelliJ.
This should run the server on port 9999 (you can leave it running in the background).
First, make sure you've run the app server in test environment as explained above.
Then, use IntelliJ to run tests in the test
directory.
You can do this by right-clicking on the test
directory in the Project explorer, then choosing "Run 'Tests in..."
(You can also run individual tests using IntelliJ).
App.kt
contains the http4k app with the routing - see https://www.http4k.org/guide/howto/simple_routing/- The
handlers
directory contains handler functions (they receive aRequest
and need to return aResponse
) - The
entities
directory contains entities (models) - see https://www.ktorm.org/en/entities-and-column-binding.html#Define-Entities - The
schemas
directory contains database schema definition code - see https://www.ktorm.org/en/schema-definition.html - The
viewmodels
directory contains "ViewModel" classes - see https://www.http4k.org/guide/reference/templating/ - The
resources
directory contains Handlebars templates - see https://mustache.github.io/ Main.kt
contains themain
function running the app as a server
http4k: https://www.http4k.org/blog/meet_http4k/ https://www.http4k.org/guide/concepts/lens/ https://www.http4k.org/guide/howto/use_html_forms/
handlebars:
ktorm
./gradlew build
# Install the latest http4k Toolbox binary:
brew tap http4k/tap && brew install http4k
# ...then test it with:
http4k --version
@TODO
How was this resource?
π« π π π π
Click an emoji to tell us.