All Projects → DanyMariaLee → Scale

DanyMariaLee / Scale

Another example of a REST API with Akka HTTP

Programming Languages

scala
5932 projects

Projects that are alternatives of or similar to Scale

typebus
Framework for building distributed microserviceies in scala with akka-streams and kafka
Stars: ✭ 14 (-39.13%)
Mutual labels:  akka, akka-http, akka-streams
khermes
A distributed fake data generator based in Akka.
Stars: ✭ 94 (+308.7%)
Mutual labels:  akka, akka-http, akka-streams
akka-http-circe-json-template
Akka HTTP REST API Project Template using Akka HTTP 10.0.4 with Circe 0.7.0 targeting Scala 2.12.x
Stars: ✭ 21 (-8.7%)
Mutual labels:  akka, akka-http, akka-streams
Otoroshi
Lightweight api management on top of a modern http reverse proxy
Stars: ✭ 177 (+669.57%)
Mutual labels:  akka-streams, akka, akka-http
akka-cookbook
提供清晰、实用的Akka应用指导
Stars: ✭ 30 (+30.43%)
Mutual labels:  akka, akka-http, akka-streams
Quark
Quark is a streaming-first Api Gateway using Akka
Stars: ✭ 13 (-43.48%)
Mutual labels:  akka, akka-http, akka-streams
Squbs
Akka Streams & Akka HTTP for Large-Scale Production Deployments
Stars: ✭ 1,365 (+5834.78%)
Mutual labels:  akka-streams, akka, akka-http
slicebox
Microservice for safe sharing and easy access to medical images
Stars: ✭ 18 (-21.74%)
Mutual labels:  akka, akka-http, akka-streams
Es Cqrs Shopping Cart
A resilient and scalable shopping cart system designed using Event Sourcing (ES) and Command Query Responsibility Segregation (CQRS)
Stars: ✭ 19 (-17.39%)
Mutual labels:  akka-streams, akka, akka-http
akka-http-actor-per-request
Example akka application that uses the actor per request model
Stars: ✭ 16 (-30.43%)
Mutual labels:  akka, akka-http
jwt-akka-http
An example how to implement a very simple authentication and authorization with Akka HTTP. Related to https://blog.codecentric.de/en/2017/09/jwt-authentication-akka-http
Stars: ✭ 23 (+0%)
Mutual labels:  akka, akka-http
akka-http-streaming-response-examples
A list of examples that involve streaming with Akka Streams and used together with Akka HTTP
Stars: ✭ 73 (+217.39%)
Mutual labels:  akka-http, akka-streams
Akka
Examples and explanations of how Akka toolkit works
Stars: ✭ 20 (-13.04%)
Mutual labels:  akka, akka-streams
ecommerce
A project for exploring Akka with Scala
Stars: ✭ 24 (+4.35%)
Mutual labels:  akka, akka-http
Akka-Streams-custom-stream-processing-examples
Demos of how to do custom stream processing using the Akka Streams GraphStages API
Stars: ✭ 13 (-43.48%)
Mutual labels:  akka, akka-streams
kamon-akka-http
Kamon integration for metrics, context and distributed tracing with Akka HTTP
Stars: ✭ 75 (+226.09%)
Mutual labels:  akka, akka-http
alpakka-samples
Example projects building Reactive Integrations using Alpakka
Stars: ✭ 61 (+165.22%)
Mutual labels:  akka, akka-streams
ssl-config
SSL configuration logic, extracted from Play's WS (for use in Akka et al).
Stars: ✭ 65 (+182.61%)
Mutual labels:  akka, akka-http
reactive-streams-for-java-developers
No description or website provided.
Stars: ✭ 16 (-30.43%)
Mutual labels:  akka-http, akka-streams
Akka Http Json
Integrate some of the best JSON libs in Scala with Akka HTTP
Stars: ✭ 530 (+2204.35%)
Mutual labels:  akka, akka-http

Scale

alt text

An example of Akka HTTP 2.5.1 library usage for building a REST service. The service itself takes median salary for the requested job title or related jobs from Glassdoor API.

What's implemented

application.conf

Since Glassdoor provides information only for registered application we need to add keys to apps configuration. To get keys go to Glassdoor API page to register your application. Configuration in your app.conf file will look like this

glassdoor {
  partner-id = "111111"
  key =	"asdffff111"
}

build.sbt

If you want to use it as an external library by calling a service directly or adding the routes

"com.github.danymarialee" %% "scale" % "1.0.0"

Usage by getting the code from github

sbt
> run

Then you'll see something like

[info] Running up.scale.Main 
[scale-service-akka.actor.default-dispatcher-5] INFO akka.event.slf4j.Slf4jLogger - Slf4jLogger started

Now you cal call the service to get median salary

curl http://localhost:9000/salary?job_title=driver

=>

{
   "data": {
       "title": "driver",
       "payMedian": 31000,
       "payCurrencyCode": "USD"
   },
   "code": 0
}

Or for related job titles

curl http://localhost:9000/salary/related?job_title=driver

=>

{
    "data": [
       {
         "title": "truck driver",
         "payMedian": 46000,
         "payCurrencyCode": "USD"
       },
       {
         "title": "delivery driver",
         "payMedian": 39000,
         "payCurrencyCode": "USD"
       },
       {
         "title": "bus driver",
         "payMedian": 26500,
         "payCurrencyCode": "USD"
       }
    ],
    "code": 0
}

Usage by calling with SalaryService

The SalaryService requires

  • ExecutionContext
  • ActorSystem
  • Materializer

Those are implicits => means need to be in the scope

import up.scale.services.SalaryService

val service = new SalaryService()

val exact = service.getJob("writer") // => Job
val related = service.getRelated("writer") // => List[Job]

Domain

case class Job(title: String, payMedian: Double, payCurrencyCode: String)

Testing

sbt
> test

=>

[test-salary-service-akka.actor.default-dispatcher-4] INFO akka.event.slf4j.Slf4jLogger - Slf4jLogger started
[info] SalaryServiceTest:
[info] The salary service
[info] - should return one job
[info] - should return related jobs
[info] GlassdoorResourceTest:
[info] The salary service
[info] - should return one job
[info] - should return related jobs
[info] - should return error from external service for related jobs request
[info] - should reject salary because of missing parameter job_title
[info] - should reject related salaries because of missing parameter job_title
[info] - should leave GET requests to other paths unhandled
[info] Run completed in 4 seconds, 102 milliseconds.
[info] Total number of tests run: 8
[info] Suites: completed 2, aborted 0
[info] Tests: succeeded 8, failed 0, canceled 0, ignored 0, pending 0
[info] All tests passed.
[success] Total time: 5 s, completed May 17, 2017 5:43:56 PM

If you have any questions my Twitter handle @besseifunction

Have fun!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].