How to create a fully functional blog with Alpas, Kotlin, and Tailwind — part 2: setup service…
Tags: coding, framework, alpas, kotlin
Published: 2020-03-12 17:37:24

---
title: How to create a fully functional blog with Alpas, Kotlin, and Tailwind — part 2: setup service…
published: true
date: 2020-03-12 17:35:00 UTC
tags: coding,framework,alpas,kotlin
canonical_url: 
---

### How to create a fully functional blog with [Alpas](https://alpas.dev), Kotlin, and Tailwind — part 2: setup service provider, markdown convertor, and controller

![](https://cdn-images-1.medium.com/max/1024/1*w1BjdpCmq1yoP1yYZeQNnw.png)

In this part 2 continuation of creating a fully functional blog with Alpas, Kotlin, and Tailwind series, we will be adding a service provider, use the Flexmark Java library to convert markdown to HTML, and build out our controller.

### Step 4: Create service provider

[_steps continued from part 1_](https://dev.to/armiedema/how-to-create-a-fully-functional-blog-with-alpas-kotlin-and-tailwind-part-1-setup-project-112g)

Service providers are classes that allow you to register and boot your services in a more controlled way in one central place. Our service provider will be simple and assist with making blogs.

1. Use the `./alpas make:provider BlogServiceProvider` command to create the service provider
2. In the **BlogServiceProvider** file, add `app.bind(Blogs(app.make()))` to the override fun boot function
3. Navigate to the **HttpKernal** file and add `BlogServiceProvider::class` to the list of providers

**Let’s next code the logic to convert markdown to HTML as well as extract some blog post meta data.**

💡 Check your progress against [BlogServiceProvider](https://github.com/armgitaar/blogify/blob/master/src/main/kotlin/providers/BlogServiceProvider.kt)

#### 📄 Related Documentation

- [Service Provider](https://alpas.dev/docs/service-providers#main)

### Step 5: Create a markdown convertor

Our blog will allow bloggers to format content using markdown. Once they save their changes, our code will convert the markdown content to HTML. We will also write some logic to read through post headers to extract meta data.

1. Create a new directory under the Kotlin directory named  **actions**
2. Under the **actions** directory, create a new file named **Markdown.kt**
3. Open **Markdown.kt** and add the code from [Blogify repo on GitHub](https://github.com/armgitaar/blogify/blob/master/src/main/kotlin/actions/Markdown.kt)

You will notice that we import the Flexmark library. If you didn’t know it already, Kotlin is compatible with Java libraries — so we can natively pull in and use the best Java based modules out there!

#### 📄 Related Documentation

- [Flexmark](https://github.com/vsch/flexmark-java)

### Step 6: Add blog retrieval and pagination functions

We will need a way to retrieve a range of blogs, retrieve blog content, and retrieve blog metadata. And, pagination to page through results on the front-end of course! Let’s create those functions now before we build out the controller.

1. Under the **actions** directory, create two new files —  **GetBlogs.kt** and **Pagination.kt**
2. Open **GetBlogs.kt** and add the code from [Blogify repo on GitHub](https://github.com/armgitaar/blogify/blob/master/src/main/kotlin/actions/GetBlogs.kt)
3. Open **Pagination.kt** and add the code from [Blogify repo on GitHub](https://github.com/armgitaar/blogify/blob/master/src/main/kotlin/actions/Pagination.kt)

Be sure to read through the code and comments to gain a good understanding of what is going on with the functions. Next up — let’s work on the controller!

### Step 7: Create blog controller

We are super close — just a few more steps!

Now it’s time to setup our blog controller.

1. Create a new controller using `./alpas make:controller BlogController`
2. In the newly created **BlogController.kt** file, copy and paste in the code from [Blogify repo on GitHub](https://github.com/armgitaar/blogify/blob/master/src/main/kotlin/controllers/BlogController.kt)

You may have noticed under the submit function we are referring to a BlogData validation rule. This is a custom rule that we will setup in the next step.

💡 Read through the code and comments to ensure a good understanding of what is going on in the controller

#### 📄 Related Documentation

- [Controllers](https://alpas.dev/docs/controllers#main)
- [Ktorm](https://ktorm.liuwj.me/)

We made a lot of great progress towards creating a fully functional blog in Step 2. Step 3 will be 90% focused on the front-end. You can always jump ahead and [look at the finished project on GitHub](https://github.com/armgitaar/blogify).

**In part 3 of this series, we will work on beautifying your blog using Tailwind CSS!**

[Read part 1](https://dev.to/armiedema/how-to-create-a-fully-functional-blog-with-alpas-kotlin-and-tailwind-part-1-setup-project-112g)
[Read part 3](https://dev.to/armiedema/how-to-create-a-fully-functional-blog-with-alpas-kotlin-and-tailwind-part-3-validation-rule-4bin)

* * *