Week 5 - HTTP and Javalin - Intro to HTTP and Javalin, Dependency Management with Maven Flashcards

1
Q

What is HTTP?

A

HTTP stands for HyperText Transfer Protocol is used to send hypermedia over the internet

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

HTTP works by

A

making a connection to a server, sending a request, and receiving a response

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

A request contains

A

contains the method used, the endpoint, and optional headers and a body

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

A response contains

A

the status code, status message, and optional headers and a body

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

A body contains

A

a resource, which is just some data

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

HTTP Methods:

A

HTTP defines a set of request methods to indicate the desired action to be performed for a given resource. Although they can also be nouns, these request methods are sometimes referred to as HTTP verbs.

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

GET requests

A

GET method is used to retrieve data from a server at the specified resource. For example, say you have an API with a /users endpoint. Making a GET request to that endpoint should return a list of all available users.

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

POST requests

A

are used to send data to the API server to create or update a resource. The data sent to the server is stored in the request body of the HTTP request.

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

PUT requests

A

are used to send data to the API to update or create a resource.

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

Difference between PUT and POST requests

A

The difference is that PUT requests are idempotent. That is, calling the same PUT request multiple times will always produce the same result. In contrast, calling a POST request repeatedly may have side effects when creating the same resource multiple times.

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

PATCH request

A

you only apply partial modifications to the resource.

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

DELETE method (request)

A

delete the resource at the specified URL

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

HEAD method

A

is almost identical to GET, except without the response body

In other words, if GET /users returns a list of users, then HEAD /users will make the same request but won’t get back the list of users.

HEAD requests are useful for checking what a GET request will return before actually making a GET request – like before downloading a large file or response body. Learn more about HEAD requests on MDN.

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

OPTIONS request

A

should return data describing what other methods and operations the server supports at the given URL.

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

Informational responses

A

(100–199)

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

Successful responses

A

(200–299)

17
Q

Redirection messages

A

(300–399)

18
Q

Client error responses

A

(400–499)

19
Q

Server error responses

A

(500–599)

20
Q

What is javalin?

A

Javalin is a lightweight web framework for building modern, scalable, and high-performance web applications in Java and Kotlin. It is designed to be simple, intuitive, and easy to use, with a minimalistic API that is focused on getting things done quickly.

21
Q

Syntax: GET javalin instance

A

Javalin app = Javalin.create().start(7000);
app.get(“/”, ctx -> ctx.result(“Hello World”));
}

22
Q

What are the three main javalin handlers?

A

before-handlers, endpoint-handlers, and after-handlers.

23
Q

Before handlers

A

Before-handlers are matched before every request (including static files).

app.before(ctx -> {
// runs before all requests
});
app.before(“/path/*”, ctx -> {
//

24
Q

Endpoint handlers

A

Endpoint handlers are the main handler type, and defines your API. You can add a GET handler to server data to a client, or a POST handler to receive some data.

Endpoint-handlers are matched in the order they are defined.

app.get(“/output”, ctx -> {
// some code
ctx.json(object);
});

app.post(“/input”, ctx -> {
// some code
ctx.status(201);
});

25
Q

After handlers

A

After-handlers run after every request (even if an exception occurred). You might know after-handlers as filters, interceptors, or middleware from other libraries.

app.after(ctx -> {
// run after all requests
});
app.after(“/path/”, ctx -> {
// runs after request to /path/

});

26
Q

The before-, endpoint- and after-handlers require three parts:

A

A verb, one of: before, get, post, put, patch, delete, after (… head, options, trace, connect)
A path, ex: /, /hello-world, /hello/{name}
A handler implementation, ex ctx -> { … }, MyClass implements Handler, etc

27
Q

The Handler interface has a void return type. You use a method like _____________ to set the response which will be returned to the us

A

ctx.result(result), ctx.json(obj), or ctx.future(future)

28
Q

Describe Maven

A

Maven is a dependency manager and build automation tool for Java programs. Maven project configuration and dependencies are handled via the Project Object Model, defined in the pom.xml file. This file contains information about the project used to build the project, including project dependencies and plugins.

29
Q

What is a package?

A

A package is a collection of classes, interfaces, and enums in a hierarchial manner.

30
Q

Why packages?

A

Packages enable you to keep your classes separate from the classes in the Java API.
Packages allow you to reuse classes in other applications.
Packages allow you to distribute your classes to others.