Scalatra Flashcards

1
Q

Name the 5 CRUD HTTP Methods

A

POST PUT PATCH GET DELETE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

When a user enters an address in the browsers location bar a ____ request is generated

A

Get

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

When should you use a GET

A
  • When you are implementing a read-only operation such as the R in CRUD
  • When the request can be submitted repeatedly.
  • When the response should be bookmarkable or indexed in search engines.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

The default method of a web form is ______ but __________________

A

POST

POST is not limited to web forms.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

The request body may contain any arbitrary data, described by the Content-Type header of the request. Other common POST bodies include

A

JSON, XML and Images

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Use POST in the following cases

A
  • When implementing create operations, such as the C in CRUD
  • When the server is responsible for generating a URI for the created entity
  • When you’re implementing a write operation and nothing else seems to fit.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

POST is a good default choice when writing because it is the only CRUD method that is not idempotent. What does this mean

A

A client should be able to resubmit a GET, DELETE or PUT request and expect the same result. A POST offers no such guarantee and is thus more flexible in its implementation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Why do web browsers issue a a warning when POST request is resubmitted

A

A client should be able to resubmit a GET, DELETE or PUT request and expect the same result. A POST offers no such guarantee.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

HTML forms only support (which methods?)

A

GET and POST

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

PUT requests are most similar to

A

POST

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Use PUT requests when

A

When implementing update operations such as the U in CRUD

When implementing create operations such as the C in CRUD

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Why is it important to follow the conventions with HTTP?

A

HTTP services are often consumed by clients that are not considered at the time of development.
Also Think of the case where developers implemented delete with simple hyperlinks.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

A HEAD Request should be treated the same as a ______ request except that it should not return a ___________________________

A

GET

Body

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

If HTTP methods declare the type of action to be performed, then route matchers declare …

A

the resources on which the action is to be performed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Name the three types of route matchers that are supported out of the box

A

Path expressions (string)
Regular expressions
Boolean expressions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

The most common type of route matcher is

A

path expression

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

A path expression always starts with a

A

/

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

get {“/artists”} which is the route matcher

A

/artists

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

class RecordStore extends ScalatraServlet { get(“/artists”) {

  Artist.getAll.map { artist =>
          ${artist.name}
 }
 }
}
which is the Action code?
A

Artist.getAll.map { artist =>

      ${artist.name}  }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

How would you parameterise a path expression

A

use a path parameter (declared by preceding it with a colon character

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

A path parameter is never …

At least ________ must be matched

A

an empty string

at least one character must be matched

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

A path parameter matches everything up to …

A

the next special character /,?, or #

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

The “/artists/?” expression would match a request to both of these

A

■ http://localhost:8080/artists

■ http://localhost:8080/artists/

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

In the literal URI, ? marks the beginning of

A

the query string

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

How is the use of ? different in the literal URI and in a path expression

A

in a path expression ? means that the preceding character is optional, in a literal URI the ? marks the beginning of a query string

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

get(“/artists/:name/info.?:format?)

what to the two ?s apply to?

A

the first ? makes the period optional the second applies to the format param

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

In this route, you use a single /downloads/* route to serve files under a virtual filesystem. You could have used /downloads/:name, but

A

ecall that named parameters match up until the next / char- acter in a URL. A splat parameter frees you from this restriction, so that you can match a path in an arbitrary directory structure.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

A route matcher returns an

A

Option[Map[String, Seq[String]]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

What does SCALA do to prevent null pointer expressions (NPE)

A

Uses an Option Type

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

How would you prevent an object of type String from returning an NPE.

A

declare it to have a type of Option[String]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q

what is “implicit”

A

a compile time decorator for doing type conversions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q

how does implicit work?

A

at compile time if there is a cast that the compiler would not know how to do it looks for an implicit function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
33
Q

If you want to use your custom converters across servlets, or if you have more than one of them, it might be a good idea to place them in a

A

trait

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
34
Q

It is possible to run (or not run) filters based on fairly complex conditional code. For example, if you wanted to run a before filter for a specific route, but only on POST requests, you could do this:

A

before(“/hackers”, request.requestMethod == Post) {
DataBase.connect;
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
35
Q

It’s possible to use ______________________ to conditionally run filters on your routes.

A

any boolean expression you can think of

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
36
Q

Sometimes you’ll need to read headers off an incoming request. You can do this using :

A

request.getHeader()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
37
Q

HTTP-based applications can accept input in a variety of ways, including form parameters, path parameters, and query parameters. Scalatra reads all of these types of parameters from incoming requests using the ________ function, which is part of the Scalatra DSL.

A

params

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
38
Q

The params function returns a _______ _____ containing all incoming parameters

A

Scala map

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
39
Q

Map keys and values are all

A

strings

40
Q

Scala’s Option type is one of the language’s key features. You can use it to

A

check your code at compile time, guarding against runtime errors.

41
Q

What is the advantage of using the ActionResult function

A

They return the proper HTTP status code for a given situation, and give an English- language explanation of your intentions

42
Q

Generally, if you intend to output JSON using Scalatra’s JSON support, your JSON routes should always return a value of type

A

JValue

43
Q

You can think of a value of type JValue as the _______representation of a JSON document, often called its ___ ____ ____

A

abstract

abstract syntax tree AST

44
Q

What are case classes?

A

plain and immutable data-holding objects that should exclusively depend on their constructor arguments.

45
Q

Two optional response header fields can be useful when serving files:

A

Content- Disposition and Content-Description.

46
Q

The Content-Disposition field contains

A

information about the processing of the file contained in the response

47
Q

If the disposition type is set to inline

A

the document in the response should be displayed directly to the user

48
Q

The current environment in which a Scalatra application runs can be read using the

A

environment method defined on ScalatraBase

49
Q

The application environment is set through the

___________________________ key either as a system property or using the ____________________________

A

The application environment is set through the org.scalatra.environment key either as a system property or using the web.xml file, found at src/main/webapp/ WEB-INF/web.xml.

50
Q

xsbt-web-plugin is an extension to __ that integrates a ____________ web application

A

sbt

servlet based

51
Q

xsbt-web-plugin, in turn, consists of three other plugins:

A

WebappPlugin, Container- Plugin, and WarPlugin.

52
Q

WebappPlugin integrates a _______________ in an sbt build.

A

web application layout

53
Q

Following the servlet standard, the WEB-INF directory—which is not publicly accessible—contains

A

the web.xml deployment descriptor and the dependency JARs in WEB-INF/lib.

54
Q

The _________________ task copies the web application resources from the web appli- cation’s source directory to the target directory.

A

webappPrepare

55
Q

The sbt-less plugin is a generator that generates

A

CSS assets from Less asset sources. It’s enabled by default.

56
Q

What is an asset pipeline

A

The asset pipeline provides a framework to concatenate and minify or compress JavaScript and CSS assets

57
Q

What does WAR stand for in .WAR file

A

A Web application archive

58
Q

in sbt you’re dealing with two different scala versions

A

he one used by sbt for the build process (depending on the sbt version) and the one used to compile your code against (configured with e.g. scalaVersion := “2.11.4” above).

59
Q

how do you know what scala version you are using

A

scala> util.Properties.versionNumberString

60
Q

how do you determine the sbt version

A

sbt sbtVersion

61
Q

where would you put the application.conf file

A

in the resources folder

62
Q

REPL

A

Read Evaluate Print Loop

63
Q

In Slick, a database table is described as a Table in Scala code. This allows it to

A

formulate statically typed queries against that table without having to write SQL.

64
Q

The type parameter T is

A

the Scala type of the column

65
Q
What does this do?
def * = (id, name, location, longitude, latitude, description)
<> (Area.tupled, Area.unapply)
A

Defines the default projection for queries to the table

66
Q

TableQuery[E]

A

a Query on the table E using the table’s default projection

67
Q

What happens when FutureSupport is mixed into your application

A

It enables asynchronous request processing

68
Q

A join can be expressed either as an _______ join or as a ______ join.

A

applicative

monadic

69
Q

There are Slick methods for each SQL join method:

A

join for cross or inner joins, and

leftJoin, rightJoin, and outerJoin.

70
Q

The monadic join style

A

uses flatMap to construct joins.

71
Q

Name 6 types of Functor

A
covariant	
contravariant	
exponential	
applicative	
monad
comonad
72
Q

Sessions are a core part of Scalatra, and you can start a session in one of several ways. The most explicit way to trigger a session is

A

mix Scalatra’s SessionSupport trait into one or more of your controllers

73
Q

What does Flashmap support do

A

“flash” short amounts of information to a user between requests

74
Q

The anatomy of any Scentry strategy is fairly simple. Strategies are just

A

Strategies are just regular Scala classes that inherit from ScentryStrategy.

75
Q

Strategies must implement two methods

A

a way to retrieve a user for authentication purposes,

a way to authenticate that the user is who they say they are.

76
Q

trait OurBasicAuthenticationSupport extends ScentrySupport[User]
with BasicAuthSupport[User] {
self: ScalatraBase => (what does this mean)

A

Any class that mixes in ourBasicAuthenticationSupport trait must inherit from ScalatraBase. In other words, this trait can only be mixed into Scalatra controllers.

77
Q
covariant	
contravariant	
exponential	
applicative	
monad
comonad

These are examples of what?

A

Functors

78
Q

What is the name of the authentication module shipped with Scalatra

A

Scentry

79
Q

Scentry triggers a

A

cookie based HTTP Session

80
Q

As soon as you extends Scalatra’s SessionSupport you are

A

setting a cookie on every request

81
Q

Scentry is ideally suited to

A

stateful authentication scenarios, where credentials are submitted at the beginning of a session as opposed to per request.

82
Q

The pluggable design of Scentry makes it simple to support several authentication mechanisms, such as

A
  • HTTP Basic
  • HTML login forms,
  • “remember-me” cookies.
83
Q

Most other languages still rely on old-style concurrency management tools like

A

locks and threads

84
Q

locks and threads can be extremely difficult to use because they are

A

non deterministic

85
Q

What does non-deterministic mean

A

you can’t necessarily reproduce your threading bugs when you want, because they can be the result of multiple threads interacting in strange and horrifying ways.

86
Q

How do you show the full stack trace inside the sbt stacktrace

A

last *:update

87
Q

scala has a few different constructs for dealing with asynchronous tasks, name two of them

A

Actors

Futures

88
Q

Adding FutureSupport means that you need to define an

A

ExecutionContext for your Futures to run in.

89
Q

How do you add an ExecutionContext for your futures to run in?

A

Adding implicit def executor = ExecutionContext.global

90
Q

here are quite a few different kinds of ExecutionContexts that you can choose from, each with differ- ent qualities. If in doubt, use

A

ExecutionContext.global

91
Q

One thing to watch out for: never close a Future …

A

over mutable state

92
Q

Where does the request variable live

A

Inside the servlet containers thread pool

93
Q

Why does the request variable living inside the servlet container’s thread pool create a conundrum for a Future?

A

he request is in the servlet container, but everything inside the Future executes in a totally different thread pool.

94
Q

What is a tuple

A

A tuple combines a fixed number of items together so that they can be passed around as a whole

95
Q

Unlike an array or list, a tuple can

A

hold objects with different types but they are also immutable.