Return different type of response based on Accept header
I don't know Akka-Http API well enough, but it looks like the if condition is misplaced. I think that it can be substituted with a matcher under case stories:

optionalHeaderValueByName("Accept") { contentType =&gt;
  complete {
    NewsService.getNewsList().map {
      case stories: List[Story] =&gt; {
        contentType match {
          case Some(protoEncode) =&gt; 
            HttpResponse(entity = HttpEntity(ContentType(protoEncoding), StoryList(stories).toProto().build().toByteArray))
          case None =&gt; StoryList(stories)
        }
      }
    }
  }
}


It seems that it is a bit too deeply nested, but at least there is no repetition on NewsService.getNewsList().map.