Image for post
Image for post

In our free Scala and Akka HTTP course we build an API for a Todo application. Original I know…

In this tutorial we will extend the API’s functionality by adding an endpoint that will allow us to search for todos.

The endpoint will accept two query parameters, we’ll extract, parse them and return the appropriate todo list.

Clone the course repo and checkout the branch 8.3-test-update-route.

Feel free to look around, when you’re ready we’ll start coding!

Implementing search in the repository

Our first step is to implement the search functionality in the repository.

If you look at our models, we’ve been creating a model for the data that each endpoint receives. …

Image for post
Image for post

Akka HTTP’s routing DSL might seem complicated at first, but once you get the hang of it you’ll see how powerful it is.

In this tutorial we will focus on creating routes and their structure. We won’t cover parsing to and from JSON, we have other tutorials that cover that topic.

What are directives?

One of the first concepts we’ll find when learning server-side Akka HTTP (there’s a client-side library as well) is directives.

So, what are they?

You can think of them as building blocks, Lego pieces if you will, that you can use to construct your routes. …

Image for post
Image for post

Even though the usual library to (un)marshal JSON in Akka HTTP applications is spray-json, I decided to give circe a try. I use it in the Akka HTTP beginners course I’m working on. *cough* it’s free 😁 *cough*

In this post I’d like to show you why I tried it out.

To use circe with Akka HTTP — and other JSON libraries for that matter — we have to create the marshalers and unmarshalers manually. Thankfully, there is an additional library that already does that for us.

Project setup and overview

Clone the project’s repository, and checkout the branch 3.3-repository-implementation.

Under src/main/scala you'll find the following…

Image for post
Image for post

Using Docker is a given nowadays. In this tutorial we will how to learn to dockerise our Scala and Akka HTTP applications without even creating a Dockerfile ourselves.

For the purposes of this tutorial, we assume Docker is already installed on the machine. If it isn’t, please follow the official documentation.

To automate the creation of the Dockerfile for our project, we will use the sbt-native-packager plugin.

You can use any Scala or Akka HTTP project for this tutorial. We will be using the following repository, feel free to clone it and make sure to checkout the branch 6.5-testing-directives.

Adding the plugin

First, we need to add the plugin to our project in the project/plugins.sbt file. If the file doesn't exist, we need to create it, and then add the following…

Image for post
Image for post

In the previous post, we added JSON support to our Akka HTTP API using circe.

This time we’ll do the same but using spray-json. Akka HTTP supports it by providing an official library — we don’t need a third-party party one like we did with circe.

Project setup

We’ll go through the same steps as the previous tutorial to set up the project.

Clone the repo, and check out the branch 3.3-repository-implementation.

We will also do the changes we did in the previous tutorial.

First, we will replace the circe dependencies with the spray-json dependency since we won’t be needing it for this tutorial. Update the build.sbt

Yes, it’s still a thing.

Image for post
Image for post
Photo by Blake Connally on Unsplash

Akka is a popular actor-based toolkit for building concurrent and distributed applications in the JVM. These applications mostly use Scala or Java.

It has several modules that help to build such applications, and Akka HTTP is one of them.

Akka HTTP has both client-side and server-side utilities. We will focus on the server in this tutorial.

You should be familiar with Scala, and you should have SBT and IntelliJ setup and installed. If that’s not the case, check the official docs.

Without further ado, let’s build a hello world API using Scala and Akka HTTP!

Project setup

Feel free to clone the repo, make sure you are using the branch 2.1-review-project. …

To tidy up your routes.

Image for post
Image for post
Photo by Fabian Grohs on Unsplash

If you’ve ever written something more complex than a Hello World API in Akka HTTP, you might have found out that the routing DSL can get quickly out of hand.

With deeply nested layers in your routes, and maybe even some code duplication.

That’s what directives are for. But what is a directive?

Directives are small, composable building blocks that allow you to create your routes piece by piece.

A typical route looks like:

pathPrefix("todos") {
pathEndOrSingleSlash {
get {
onComplete(todoRepository.all()) {
case Success(todos) =>
case Failure(exception) =>
complete(ApiError.generic.statusCode, ApiError.generic.message) …

Which one should you pursue?

Image for post
Image for post
Photo by Jesus Hilario H. on Unsplash

Pursuing too many passions often feels like being stretched in different directions. You do it for too long and you’ll be torn apart.

I’ve been there multiple times. I just don’t learn.

At some point in my life I’ve dedicated considerable time to my many passions. Drawing, writing, playing video games, swimming, programming, learning entrepreneurship, dancing, and the list goes on.

I’ve even tried to learn how to play the tin whistle multiple times. I love Irish music.

But sadly, there’s only so much time in your day.

It’s no surprise most of the advice you’re given in your career and life is to focus on a single skill or path to master it. …

It’s been quite a ride.

Image for post
Image for post
Photo by Mantas Hesthaven on Unsplash

It’s been six months since I moved from San José, Costa Rica to Manchester, UK.

Moving countries has been one of my life goals for as long as I can remember. While Costa Rica isn’t a bad country to live in, I’ve never felt like it’s a place I’d like to settle.

Leaving everything you know behind isn’t easy, family, friends, your routine and in my case my job as well.

I never could decide on where I wanted to live, so I just started looking for jobs I’d like, applied, and took what seemed the best option at the time. …

What if you could know?

Image for post
Image for post
Photo by Pixabay on Pexels

Would you choose to know if you could?

Could you really handle knowing whether your relationship will end or not?

What if you cared deeply about that person and knew your relationship has an expiration date, but you just don’t know when exactly?

Would you prefer to end it straightaway?

Feel a little bit of pain early on to avoid great deals of pain in the future.

Focus your time on finding someone that doesn’t come with an expiration date.

But then you’d wonder what could have happened.

All those conversations you were eagerly waiting to have with them gone. …


Miguel Lopez

🚀 Developing microservices with Scala, Akka, Kafka and AWS at Disney Streaming Services. 💻 Free Akka HTTP course:

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store