Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Basic server with GET and POST resources and mock in-memory DB

Notifications You must be signed in to change notification settings

sunshah/akka_http

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Introduction

Akka HTTP is a lightweight implementation of a full HTTP server and client stacks on top of akka-actor and akka-stream. It is ideal for providing itegration between RESTful services as opposed to having a full framework. Read more here

This very basic example allows users to create an order made up of items. Here are the class definitions:

final case class Item(name: String, id: Long)
final case class Order(items: List[Item])

Backend is a basic in-memory DB that holds data for duration of the application

Usage

Checkout the code and use sbt to fire up sbt shell.

Run the server

~run

The server should be up and running, it defaults to port 8080. Open up a browser and enter http://localhost:8080

You should see a Server is up and running message

Creating and viewing Orders and Items using curl:

GET root

curl -vv http://localhost:8080/

POST list of items to be added to the order

curl -vv -X POST -H 'Content-Type: application/json' -d '{"items": [{"name" : "item1", "id" : 1}, {"name": "item2", "id": 2}]}' http://localhost:8080/order

GET list of items in the order

curl -vv http://localhost:8080/order

GET specific items by id

curl -vv http://localhost:8080/item/1

About

Basic server with GET and POST resources and mock in-memory DB

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages