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
How is the use of ? different in the literal URI and in a path expression
in a path expression ? means that the preceding character is optional, in a literal URI the ? marks the beginning of a query string
26
get("/artists/:name/info.?:format?) | what to the two ?s apply to?
the first ? makes the period optional the second applies to the format param
27
In this route, you use a single /downloads/* route to serve files under a virtual filesystem. You could have used /downloads/:name, but
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.
28
A route matcher returns an
Option[Map[String, Seq[String]]
29
What does SCALA do to prevent null pointer expressions (NPE)
Uses an Option Type
30
How would you prevent an object of type String from returning an NPE.
declare it to have a type of Option[String]
31
what is "implicit"
a compile time decorator for doing type conversions
32
how does implicit work?
at compile time if there is a cast that the compiler would not know how to do it looks for an implicit function
33
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
trait
34
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:
before("/hackers", request.requestMethod == Post) { DataBase.connect; }
35
It’s possible to use ______________________ to conditionally run filters on your routes.
any boolean expression you can think of
36
Sometimes you’ll need to read headers off an incoming request. You can do this using :
request.getHeader()
37
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.
params
38
The params function returns a _______ _____ containing all incoming parameters
Scala map
39
Map keys and values are all
strings
40
Scala’s Option type is one of the language’s key features. You can use it to
check your code at compile time, guarding against runtime errors.
41
What is the advantage of using the ActionResult function
They return the proper HTTP status code for a given situation, and give an English- language explanation of your intentions
42
Generally, if you intend to output JSON using Scalatra’s JSON support, your JSON routes should always return a value of type
JValue
43
You can think of a value of type JValue as the _______representation of a JSON document, often called its ___ ____ ____
abstract | abstract syntax tree AST
44
What are case classes?
plain and immutable data-holding objects that should exclusively depend on their constructor arguments.
45
Two optional response header fields can be useful when serving files:
Content- Disposition and Content-Description.
46
The Content-Disposition field contains
information about the processing of the file contained in the response
47
If the disposition type is set to inline
the document in the response should be displayed directly to the user
48
The current environment in which a Scalatra application runs can be read using the
environment method defined on ScalatraBase
49
The application environment is set through the | ___________________________ key either as a system property or using the ____________________________
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
xsbt-web-plugin is an extension to __ that integrates a ____________ web application
sbt | servlet based
51
xsbt-web-plugin, in turn, consists of three other plugins:
WebappPlugin, Container- Plugin, and WarPlugin.
52
WebappPlugin integrates a _______________ in an sbt build.
web application layout
53
Following the servlet standard, the WEB-INF directory—which is not publicly accessible—contains
the web.xml deployment descriptor and the dependency JARs in WEB-INF/lib.
54
The _________________ task copies the web application resources from the web appli- cation’s source directory to the target directory.
webappPrepare
55
The sbt-less plugin is a generator that generates
CSS assets from Less asset sources. It’s enabled by default.
56
What is an asset pipeline
The asset pipeline provides a framework to concatenate and minify or compress JavaScript and CSS assets
57
What does WAR stand for in .WAR file
A Web application archive
58
in sbt you're dealing with two different scala versions
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
how do you know what scala version you are using
scala> util.Properties.versionNumberString
60
how do you determine the sbt version
sbt sbtVersion
61
where would you put the application.conf file
in the resources folder
62
REPL
Read Evaluate Print Loop
63
In Slick, a database table is described as a Table in Scala code. This allows it to
formulate statically typed queries against that table without having to write SQL.
64
The type parameter T is
the Scala type of the column
65
``` What does this do? def * = (id, name, location, longitude, latitude, description) <> (Area.tupled, Area.unapply) ```
Defines the default projection for queries to the table
66
TableQuery[E]
a Query on the table E using the table’s default projection
67
What happens when FutureSupport is mixed into your application
It enables asynchronous request processing
68
A join can be expressed either as an _______ join or as a ______ join.
applicative | monadic
69
There are Slick methods for each SQL join method:
join for cross or inner joins, and | leftJoin, rightJoin, and outerJoin.
70
The monadic join style
uses flatMap to construct joins.
71
Name 6 types of Functor
``` covariant contravariant exponential applicative monad comonad ```
72
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
mix Scalatra’s SessionSupport trait into one or more of your controllers
73
What does Flashmap support do
“flash” short amounts of information to a user between requests
74
The anatomy of any Scentry strategy is fairly simple. Strategies are just
Strategies are just regular Scala classes that inherit from ScentryStrategy.
75
Strategies must implement two methods
a way to retrieve a user for authentication purposes, | a way to authenticate that the user is who they say they are.
76
trait OurBasicAuthenticationSupport extends ScentrySupport[User] with BasicAuthSupport[User] { self: ScalatraBase => (what does this mean)
Any class that mixes in ourBasicAuthenticationSupport trait must inherit from ScalatraBase. In other words, this trait can only be mixed into Scalatra controllers.
77
``` covariant contravariant exponential applicative monad comonad ``` These are examples of what?
Functors
78
What is the name of the authentication module shipped with Scalatra
Scentry
79
Scentry triggers a
cookie based HTTP Session
80
As soon as you extends Scalatra's SessionSupport you are
setting a cookie on every request
81
Scentry is ideally suited to
stateful authentication scenarios, where credentials are submitted at the beginning of a session as opposed to per request.
82
The pluggable design of Scentry makes it simple to support several authentication mechanisms, such as
- HTTP Basic - HTML login forms, - “remember-me” cookies.
83
Most other languages still rely on old-style concurrency management tools like
locks and threads
84
locks and threads can be extremely difficult to use because they are
non deterministic
85
What does non-deterministic mean
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
How do you show the full stack trace inside the sbt stacktrace
last *:update
87
scala has a few different constructs for dealing with asynchronous tasks, name two of them
Actors | Futures
88
Adding FutureSupport means that you need to define an
ExecutionContext for your Futures to run in.
89
How do you add an ExecutionContext for your futures to run in?
Adding implicit def executor = ExecutionContext.global
90
here are quite a few different kinds of ExecutionContexts that you can choose from, each with differ- ent qualities. If in doubt, use
ExecutionContext.global
91
One thing to watch out for: never close a Future ...
over mutable state
92
Where does the request variable live
Inside the servlet containers thread pool
93
Why does the request variable living inside the servlet container's thread pool create a conundrum for a Future?
he request is in the servlet container, but everything inside the Future executes in a totally different thread pool.
94
What is a tuple
A tuple combines a fixed number of items together so that they can be passed around as a whole
95
Unlike an array or list, a tuple can
hold objects with different types but they are also immutable.