My talk at Scala Bay Meetup at Netflix about Powering the Partner APIs with Scalatra and Netflix OSS. This talk was delivered on September 9th 2013, at 8 PM at Netflix, Los Gatos.
19. /**
Lets try to build a login endpoint. It should support a method called
login(user:String,pass:String) that returns an Option[String].
*/
class LoginManagerSpec extends FlatSpec with ShouldMatchers {
}
20. /**
Lets try to build a login endpoint. It should support a method called
login(user:String,pass:String) that returns an Option[String].
*/
class LoginManagerSpec extends FlatSpec with ShouldMatchers {
it should " Be able to login a valid user and get a token " in {
fail()
}
}
21. /**
Lets try to build a login endpoint. It should support a method called
login(user:String,pass:String) that returns an Option[String].
*/
class LoginManagerSpec extends FlatSpec with ShouldMatchers {
it should " Be able to login a valid user and get a token " in {
val token = LoginManager.login("someuser", "somepassword")
token should not be None
}
}
22. /**
Lets try to build a login endpoint. It should support a method called
login(user:String,pass:String) that returns an Option[String].
*/
class LoginManagerSpec extends FlatSpec with ShouldMatchers {
it should " Be able to login a valid user and get a token " in {
val token = LoginManager.login("someuser", "somepassword")
token should not be None
}
it should " Fail to login an invalid user " in {
fail
}
}
23. /**
Lets try to build a login endpoint. It should support a method called
login(user:String,pass:String) that returns an Option[String].
*/
class LoginManagerSpec extends FlatSpec with ShouldMatchers {
it should " Be able to login a valid user and get a token " in {
val token = LoginManager.login("someuser", "somepassword")
token should not be None
}
it should " Fail to login an invalid user " in {
val token = LoginManager.login("fail", "fail")
token should be (None)
}
}
34. class LoginServiceSpec extends ScalatraFlatSpec {
addServlet(classOf[LoginService], "/*")
it should "log in valid users" in {
post("/", body = """user=gooduser&password=goodpassword""") {
status should equal(200)
body should include "token"
}
}
}
35. class LoginServiceSpec extends ScalatraFlatSpec {
addServlet(classOf[LoginService], "/*")
it should "log in valid users" in {
post("/", body = """user=gooduser&password=goodpassword""") {
status should equal(200)
body should include "token"
}
}
it should "not allow invalid users to log in" in {
post("/", body = """user=baduser&password=badpassword""") {
status should equal(401)
body should include "message"
}
}
}
36. APIs Best Practices
Use Proper HTTP Response Codes
Set Proper HTTP Headers
Break up your data into groups
42. Git Workflow
$ git status
# On branch dev
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: src/main/scala/com/netflix/nrdportal/http/DpiService.scala
# modified: src/test/scala/com/netflix/nrdportal/http/DpiServiceSpec.scala
43. Automated Code Pushes
Push to dev
Jenkins runs
dev build,
tests, merges
to master
Jenkins runs
master build,
makes an
RPM
Aminator
bakes an AMI
from the RPM
asgard
deploys the
AMI in staging
cloud