Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/vladimirlogachev/page-title-reader-microservice

Coding assessment (Scala 2, Akka HTTP) 2018
https://github.com/vladimirlogachev/page-title-reader-microservice

Last synced: 19 days ago
JSON representation

Coding assessment (Scala 2, Akka HTTP) 2018

Awesome Lists containing this project

README

        

# page-title-reader-microservice

Coding assessment (Scala 2, Akka HTTP).

Completed in 2018, and currently maintained as a demonstration project.

## Pre-requisites

- [sbt](https://www.scala-sbt.org/)

## Usage

- `sbt run` - run
- `sbt styleFix` - fix formatting and linting errors
- `sbt styleCheck` - check for formatting and linting errors
- `sbt dev` - allow compiler warnings to not fail the compilation

## What the microservice does

Give urls, get page titles

1. It gets page title for each of given url's in a list.
1. If URL is presented several times, it will be fetched once, but result will be printed several times, in the same order as in a source list.
1. It does not follow redirects immediately. Instead, it responds with a new location, so you can handle redirection before getting a final result.
1. It handles non-urls, empty strings, inaccessible hosts and http codes in a predictable manner

It works well against cases like these:

```sh
curl -H 'Content-Type: application/json' \
-d '[
"https://ya.ru",
"www.dictionary.com/browse/http",
"https://api.github.com/",
"http://ya.ru",
"nonsense://yandex.ru",
"https://github.com/ladsgfadg",
"adsfgasdfg",
"",
"https://ya.ru"
]' \
-X POST \
http://localhost:8080

```

... which result in:

```json
[
{ "url": "https://ya.ru", "title": "Яндекс — быстрый поиск в интернете" },
{
"url": "www.dictionary.com/browse/http",
"error": "Redirect: https://www.dictionary.com/browse/http"
},
{ "url": "https://api.github.com/", "error": "Page has no title" },
{ "url": "http://ya.ru", "error": "Redirect: https://ya.ru/" },
{ "url": "nonsense://yandex.ru", "error": "Bad url" },
{ "url": "https://github.com/ladsgfadg", "error": "Status code: 404" },
{ "url": "adsfgasdfg", "error": "Inaccessible host" },
{ "url": "", "error": "Inaccessible host" },
{ "url": "https://ya.ru", "title": "Яндекс — быстрый поиск в интернете" }
]
```