Scalatra Flashcards
Name the 5 CRUD HTTP Methods
POST PUT PATCH GET DELETE
When a user enters an address in the browsers location bar a ____ request is generated
Get
When should you use a GET
- 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.
The default method of a web form is ______ but __________________
POST
POST is not limited to web forms.
The request body may contain any arbitrary data, described by the Content-Type header of the request. Other common POST bodies include
JSON, XML and Images
Use POST in the following cases
- 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.
POST is a good default choice when writing because it is the only CRUD method that is not idempotent. What does this mean
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.
Why do web browsers issue a a warning when POST request is resubmitted
A client should be able to resubmit a GET, DELETE or PUT request and expect the same result. A POST offers no such guarantee.
HTML forms only support (which methods?)
GET and POST
PUT requests are most similar to
POST
Use PUT requests when
When implementing update operations such as the U in CRUD
When implementing create operations such as the C in CRUD
Why is it important to follow the conventions with HTTP?
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.
A HEAD Request should be treated the same as a ______ request except that it should not return a ___________________________
GET
Body
If HTTP methods declare the type of action to be performed, then route matchers declare …
the resources on which the action is to be performed.
Name the three types of route matchers that are supported out of the box
Path expressions (string)
Regular expressions
Boolean expressions
The most common type of route matcher is
path expression
A path expression always starts with a
/
get {“/artists”} which is the route matcher
/artists
class RecordStore extends ScalatraServlet { get(“/artists”) {
Artist.getAll.map { artist =>
${artist.name} } } } which is the Action code?
Artist.getAll.map { artist =>
${artist.name} }
How would you parameterise a path expression
use a path parameter (declared by preceding it with a colon character
A path parameter is never …
At least ________ must be matched
an empty string
at least one character must be matched
A path parameter matches everything up to …
the next special character /,?, or #
The “/artists/?” expression would match a request to both of these
■ http://localhost:8080/artists
■ http://localhost:8080/artists/
In the literal URI, ? marks the beginning of
the query string