Skip to content

Instantly share code, notes, and snippets.

View dsugden's full-sized avatar

Dave Sugden dsugden

  • Shopify
  • Gatineau
View GitHub Profile
@dsugden
dsugden / gist:b3db9008d156f7488ac6
Last active August 29, 2015 14:05
Accept Header example
GET /user/1 HTTP/1.1
Accept: application/vnd.company.app.user-v2+json
HTTP/1.1 200 OK
Content-Type: application/vnd.company.app.user-v2+json
{"user":
{"email":"bob@gmail.com"}
}
import org.json4s.{DefaultFormats, Formats}
object Json4sProtocol extends Json4sSupport {
implicit def json4sFormats: Formats = DefaultFormats
}
@dsugden
dsugden / gist:ce018faada463e1e19e6
Created September 1, 2014 12:22
Spray Custom Media Types
/**
* Foo Version Media Types for v1 and v2
*/
object VersionMediaTypes{
lazy val `application/vnd.ww.v2.foo+json` =
MediaTypes.register(MediaType.custom("application/vnd.ww.v2.foo+json"))
lazy val `application/vnd.ww.v1.foo+json` =
MediaTypes.register(MediaType.custom("application/vnd.ww.v1.foo+json"))
}
@dsugden
dsugden / FooProtocol.scala
Created September 1, 2014 12:38
Marshalling with ContentTypes
/**
* FooProtocol v1
*/
object FooProtocol {
sealed trait FooActorMessage
case class HelloFoo(hi: String) extends FooActorMessage
case class FooResponse(helloBackTo: String) extends FooActorMessage
import Json4sProtocol._
import org.json4s.native.Serialization.{read,write => swrite}
@dsugden
dsugden / FooProtocolV2.scala
Created September 1, 2014 12:42
Marshalling with ContentTypes
/**
* FooProtocol v2
*/
object FooProtocolV2 {
sealed trait FooActorMessage
case class HelloFoo(hi: String, there:String) extends FooActorMessage
case class FooResponse(helloBackTo: String) extends FooActorMessage
import examples.Json4sProtocol._
@dsugden
dsugden / FooRoute.scala
Created September 1, 2014 12:49
Spray Routes with API versioning
/**
* Foo restful interface.
*/
trait FooRoute extends HttpService with AskSupport {
import examples.FooProtocol._
import examples.FooProtocolV2._
implicit val timeout: Timeout
implicit val fooActorPath: ActorPath
@dsugden
dsugden / upickleakkahttp.scala
Last active August 29, 2015 14:12
upickle akka-http
import akka.http.marshalling._
import akka.http.model._
import akka.http.unmarshalling.{FromResponseUnmarshaller, FromRequestUnmarshaller, Unmarshaller}
import akka.stream.FlowMaterializer
import upickle.{Writer, Reader}
import scala.concurrent.duration._
import scala.concurrent.{ExecutionContext, Future}
import scala.language.implicitConversions
version = "1.0.0"
name = "singlemicro"
system = "singlemicro-1.0.0"
nrOfCpus = 1.0
memory = 67108864
diskSpace = 5000000
roles = ["backend"]
components = {
"singlemicro-1.0.0" = {
description = "singlemicro"
enablePlugins(JavaAppPackaging,ConductRPlugin)
BundleKeys.nrOfCpus := 1.0
BundleKeys.memory := 10.MiB
BundleKeys.diskSpace := 5.MB
BundleKeys.endpoints := Map("singlemicro" -> Endpoint("http",0,services = Set(URI("http:/singlemicro"))))
akka.remote {
netty.tcp {
hostname = "127.0.0.1"
port = 8089
}
}