Skip to content

Commit 48431b6

Browse files
committed
Grammar corrections
1 parent 7d388d5 commit 48431b6

7 files changed

+50
-50
lines changed

_overviews/toolkit/web-server-cookies-and-decorators.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@ next-page:
1111

1212
## Using cookies
1313

14-
Cookies are saved by adding them to the `cookies` parameter of `cask.Response` constructor.
14+
Cookies are saved by adding them to the `cookies` parameter of the `cask.Response` constructor.
1515

16-
In this example we are building a rudimentary authentication service. The `getLogin` method provides a form where
17-
username and password can be inputted. The `postLogin` reads the credentials and if they match the expected ones, a session
18-
identifier is generated, saved in the application state and sends back a cookie with the identifier.
16+
In this example, we are building a rudimentary authentication service. The `getLogin` method provides a form where
17+
username and password can be inputted. The `postLogin` reads the credentials and, if they match the expected ones, a session
18+
identifier is generated, saved in the application state, and sends back a cookie with the identifier.
1919

20-
Cookies can be read either with a method parameter with `cask.Cookie` type or by accessing `cask.Request` directly.
21-
If using the former method, names of parameters have to match the names of cookies. If a cookie with matching name is not
22-
found, an error response will be returned. In the `checkLogin` function the former method is used, as the cookie is not
23-
present before user logs in.
20+
Cookies can be read either with a method parameter of `cask.Cookie` type or by accessing `cask.Request` directly.
21+
If using the former method, the names of parameters have to match the names of cookies. If a cookie with a matching name is not
22+
found, an error response will be returned. In the `checkLogin` function, the former method is used, as the cookie is not
23+
present before the user logs in.
2424

25-
To delete a cookie set its `expires` parameter to an instant in the past, for example `Instant.EPOCH`.
25+
To delete a cookie, set its `expires` parameter to an instant in the past, for example `Instant.EPOCH`.
2626

2727
{% tabs web-server-cookies-1 class=tabs-scala-version %}
2828
{% tab 'Scala 2' %}
@@ -144,7 +144,7 @@ object MyApp extends cask.MainRoutes:
144144
Decorators can be used for extending endpoints functionality with validation or new parameters. They are defined by extending
145145
`cask.RawDecorator` class and then used as annotations.
146146

147-
In this example, the `loggedIn` decorator is used for checking if user is logged in before accessing the `/decorated`
147+
In this example, the `loggedIn` decorator is used to check if the user is logged in before accessing the `/decorated`
148148
endpoint.
149149

150150
The decorator class can pass additional arguments to the decorated endpoint using a map. The passed arguments are available

_overviews/toolkit/web-server-dynamic.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ object MyApp extends cask.MainRoutes:
3939
{% endtab %}
4040
{% endtabs %}
4141

42-
The example above creates an endpoint returning the current date and time available at `/time`. The exact response will be
42+
The example above creates an endpoint, returning the current date and time available at `/time`. The exact response will be
4343
recreated every time you refresh the webpage.
4444

45-
Since the endpoint method has `String` output type, the result will be sent with `text/plain` [content type](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type).
46-
If you want an HTML output being interpreted by the browser, you else need to set the `Content-Type` header manually
45+
Since the endpoint method has the `String` output type, the result will be sent with `text/plain` [content type](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type).
46+
If you want an HTML output to be interpreted by the browser, you will need to set the `Content-Type` header manually
4747
or [use the Scalatags templating library](/toolkit/web-server-dynamic.html#using-html-templates), supported by Cask.
4848

4949
### Running the example
@@ -71,15 +71,15 @@ In the terminal, the following command will start the server:
7171
{% endtab %}
7272
{% endtabs %}
7373

74-
Access [the endpoint](http://localhost:8080/time). You should see a result similar to the one below.
74+
Access the endpoint at [http://localhost:8080/time](http://localhost:8080/time). You should see a result similar to the one below.
7575

7676
```
7777
Current date is: 2024-07-22T09:07:05.752534+02:00[Europe/Warsaw]
7878
```
7979

8080
## Using path segments
8181

82-
Cask gives you the ability to access segments of the URL path withing the endpoint function.
82+
Cask gives you the ability to access segments of the URL path within the endpoint function.
8383
Building on the example above, you can add a segment to specify that the endpoint should return the date and time
8484
in a given city.
8585

@@ -129,10 +129,10 @@ object MyApp extends cask.MainRoutes:
129129
{% endtabs %}
130130

131131
In the example above, the `:city` segment in `/time/:city` is available through the `city` argument of the endpoint method.
132-
The name of the argument must be identical to the segment name. The `getZoneIdForCity` helper method find the timezone for
133-
a given city and then the current date and time is translated to that timezone.
132+
The name of the argument must be identical to the segment name. The `getZoneIdForCity` helper method finds the timezone for
133+
a given city, and then the current date and time are translated to that timezone.
134134

135-
Accessing [the endpoint](http://localhost:8080/time/Paris) (notice the `Paris` segment in the URL) will result with:
135+
Accessing the endpoint at[http://localhost:8080/time/Paris](http://localhost:8080/time/Paris) will result in:
136136
```
137137
Current date is: 2024-07-22T09:08:33.806259+02:00[Europe/Paris]
138138
```
@@ -233,5 +233,5 @@ object MyApp extends cask.MainRoutes:
233233
{% endtab %}
234234
{% endtabs %}
235235

236-
Here we get the text of response and wrap it in a Scalatags template. Notice that the return type changed from `String`
236+
Here we get the text of the response and wrap it in a Scalatags template. Notice that the return type changed from `String`
237237
to `doctype`.

_overviews/toolkit/web-server-input.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@ object MyApp extends cask.MainRoutes:
163163
{% endtab %}
164164
{% endtabs %}
165165

166-
In this example the JSON is merely converted to `String`, check the [*uPickle tutorial*](/toolkit/json-intro.html) for more information
167-
on what can be done with `ujson.Value` type.
166+
In this example the JSON is merely converted to `String`. Check the [*uPickle tutorial*](/toolkit/json-intro.html) for more information
167+
on what can be done with the `ujson.Value` type.
168168

169169
Send a POST request.
170170
```shell
@@ -180,11 +180,11 @@ The server will respond with:
180180

181181
## Handling JSON-encoded output
182182

183-
Cask endpoint can return JSON objects returned by uPickle library functions. Cask will automatically handle the `ujson.Value`
183+
Cask endpoints can return JSON objects returned by uPickle library functions. Cask will automatically handle the `ujson.Value`
184184
type and set the `Content-Type` header to `application/json`.
185185

186-
In this example `TimeData` case class stores the information about the time zone and current time in a chosen
187-
location. To serialize a case class into JSON, use type class derivation or define the serializer in its companion object in case of Scala 2.
186+
In this example, the `TimeData` case class stores the information about the time zone and current time in a chosen
187+
location. To serialize a case class into JSON, use type class derivation or define the serializer in its companion object in the case of Scala 2.
188188

189189
{% tabs web-server-input-4 class=tabs-scala-version %}
190190
{% tab 'Scala 2' %}
@@ -216,7 +216,7 @@ object MyApp extends cask.MainRoutes {
216216
{% tab 'Scala 3' %}
217217
```scala
218218
object MyApp extends cask.MainRoutes {
219-
import upickle.default.{ReadWriter, macroRW, writeJs}
219+
import upickle.default.{ReadWriter, writeJs}
220220
case class TimeData(timezone: Option[String], time: String) derives ReadWriter
221221

222222
private def getZoneIdForCity(city: String): Option[ZoneId] =

_overviews/toolkit/web-server-intro.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ next-page: web-server-static
99

1010
Cask is an HTTP micro-framework, providing a simple and flexible way to build web applications.
1111

12-
Its main focus is on the ease of use, which makes it ideal for newcomers, at cost of eschewing some features other
12+
Its main focus is on the ease of use, which makes it ideal for newcomers, at the cost of eschewing some features other
1313
frameworks provide, like asynchronicity.
1414

15-
To define an endpoint it's enough to annotate a function with an appropriate annotation, specifying the request path.
16-
Cask allows for building the response manually using tools the Cask library provides, specifying the content, headers,
17-
status code etc. An endpoint function can also just return a string, [uPickle](https://com-lihaoyi.github.io/upickle/) JSON type, or a [Scalatags](https://com-lihaoyi.github.io/scalatags/)
15+
To define an endpoint it's enough to annotate a function with an annotation specifying the request path.
16+
Cask allows for building the response manually using tools Cask library provides, specifying the content, headers,
17+
status code, etc. An endpoint function can also just return a string, a [uPickle](https://com-lihaoyi.github.io/upickle/) JSON type, or a [Scalatags](https://com-lihaoyi.github.io/scalatags/)
1818
template and Cask will automatically create a response, setting all the necessary headers.
1919

20-
Cask comes bundled with uPickle library for handling JSONs, supports WebSockets and allows for extending endpoints with
20+
Cask comes bundled with the uPickle library for handling JSONs, supports WebSockets and allows for extending endpoints with
2121
decorators, which can be used to handle authentication or rate limiting.
2222

2323
{% include markdown.html path="_markdown/install-cask.md" %}

_overviews/toolkit/web-server-query-parameters.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ next-page: web-server-input
1010
{% include markdown.html path="_markdown/install-cask.md" %}
1111

1212
Query parameters are the key-value pairs coming after the question mark in a URL. They can be used for filtering,
13-
sorting or limiting the results provided by the server. For example, in `<host>/time?city=Paris` URL, the `city` part
14-
is the name of a parameter and `Paris` is its value. Cask allows for reading the query parameters by defining an endpoint
13+
sorting or limiting the results provided by the server. For example, in the `<host>/time?city=Paris` URL, the `city` part
14+
is the name of a parameter, and `Paris` is its value. Cask allows for reading the query parameters by defining an endpoint
1515
method with arguments matching the names of the expected parameters and not matching any of the URL segments.
1616

17-
In this example the `city` parameter will be optional, which you specify in Cask by giving the argument `Option` type and
17+
In this example, the `city` parameter will be optional, which you specify in Cask by giving the argument `Option` type and
1818
`None` default value. If not provided, the time for the current timezone will be returned.
1919

2020
{% tabs web-server-query-1 class=tabs-scala-version %}
@@ -67,7 +67,7 @@ object MyApp extends cask.MainRoutes:
6767
{% endtab %}
6868
{% endtabs %}
6969

70-
Run the example as before and access the [endpoint](http://localhost:8080/time?city=Paris) (notice the `?city=Paris` part of the URL).
70+
Run the example as before and access the endpoint at [http://localhost:8080/time?city=Paris](http://localhost:8080/time?city=Paris).
7171
You should get a result similar to the following one.
7272
```
7373
Current date is: 2024-07-22T10:08:18.218736+02:00[Europe/Paris]

_overviews/toolkit/web-server-static.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ next-page: web-server-dynamic
1111

1212
## Serving a static file
1313

14-
An endpoint is a specific URL where a particular webpage can be accessed. In Cask an endpoint is a function returning the
14+
An endpoint is a specific URL where a particular webpage can be accessed. In Cask, an endpoint is a function returning the
1515
webpage data together with an annotation describing the URL it's available at.
1616

17-
To create a static file serving endpoint we need two things: an HTML file with the page content and a function that
18-
points out to the location of the file.
17+
To create a static file serving endpoint, we need two things: an HTML file with the page content and a function that
18+
points out the location of the file.
1919

20-
Create a minimal HTML file named `hello.html` with following contents.
20+
Create a minimal HTML file named `hello.html` with the following contents.
2121

2222
```html
2323
<!doctype html>
@@ -89,18 +89,18 @@ object Example extends cask.MainRoutes:
8989
{% endtab %}
9090
{% endtabs %}
9191

92-
In the example above, `@cask.staticFiles` instructs the server to look for files accessed at `/static` path in the
92+
In the example above, `@cask.staticFiles` instructs the server to look for files accessed at the `/static` path in the
9393
`src/main/resources` directory. Cask will match any subpath coming after `/static` and append it to the directory path.
9494
If you access the `/static/hello.html` file, it will serve the file available at `src/main/resources/hello.html`.
9595
The directory path can be any path available to the server, relative or not. If the requested file cannot be found in the
9696
specified location, a 404 response with an error message will be returned instead.
9797

98-
The `Example` object inherits from `cask.MainRoutes` class, providing the main function starting the server. The `initialize()`
99-
method call initializes the server routes, i.e. the association between URL paths and the code that handles them.
98+
The `Example` object inherits from the `cask.MainRoutes` class, providing the main function that starts the server. The `initialize()`
99+
method call initializes the server routes, i.e., the association between URL paths and the code that handles them.
100100

101101
### Using the resources directory
102102

103-
The `@cask.staticResources` annotation works in the same way as `@cask.staticFiles` used above with the difference that
103+
The `@cask.staticResources` annotation works in the same way as the `@cask.staticFiles` used above, with the difference that
104104
the path returned by the endpoint method describes the location of files _inside_ the resources directory. Since the
105105
previous example conveniently used the resources directory, it can be simplified with `@cask.staticResources`.
106106

@@ -126,9 +126,9 @@ object Example extends cask.MainRoutes:
126126
{% endtab %}
127127
{% endtabs %}
128128

129-
In the endpoint method the location is set to `"."`, telling the server that the files are available directly in the
129+
In the endpoint method, the location is set to `"."`, telling the server that the files are available directly in the
130130
resources directory. In general, you can use any nested location within the resources directory, for instance you could opt
131-
for placing your HTML files in `static` directory inside the resources directory or use different directories to sort out
131+
for placing your HTML files in the `static` directory inside the resources directory or using different directories to sort out
132132
files used by different endpoints.
133133

134134
## Running the example

_overviews/toolkit/web-server-websockets.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ next-page: web-server-cookies-and-decorators
1111

1212
You can create a WebSocket endpoint by using the `@cask.websocket` annotation. The endpoint method can return either a
1313
`cask.WsHandler` instance defining how the communication should take place, or a `cask.Response`, which rejects the
14-
attempt of forming a WebSocket connection.
14+
attempt at forming a WebSocket connection.
1515

16-
The connection can also be closed by sending `cask.Ws.close()` message through the WebSocket channel.
16+
The connection can also be closed by sending a `cask.Ws.close()` message through the WebSocket channel.
1717

18-
Create an HTML file named `websockets.html` with the following content and place it in `resources ` directory.
18+
Create an HTML file named `websockets.html` with the following content and place it in the `resources ` directory.
1919

2020
```html
2121
<!DOCTYPE html>
@@ -52,9 +52,9 @@ Create an HTML file named `websockets.html` with the following content and place
5252
```
5353

5454
The JavaScript code opens a WebSocket connection using the `ws://localhost:8080/websocket` endpoint. The `ws.onmessage`
55-
event handler is executed when server pushes a message to the browser and `ws.onclose` when the connection is closed.
55+
event handler is executed when the server pushes a message to the browser and `ws.onclose` when the connection is closed.
5656

57-
Create an endpoint for serving static files using `@cask.staticResources` annotation and the endpoint for handling
57+
Create an endpoint for serving static files using the `@cask.staticResources` annotation and an endpoint for handling
5858
the WebSocket connection.
5959

6060
{% tabs web-server-websocket-1 class=tabs-scala-version %}
@@ -109,5 +109,5 @@ def websocket(): cask.WsHandler =
109109
{% endtabs %}
110110

111111
In the `cask.WsHandler` we define a `cask.WsActor` which reacts to events (of `cask.util.Ws.Event` type) and uses
112-
WebSocket channel to send messages. In this example we receive a name of city and return the current time there. If server
112+
WebSocket channel to send messages. In this example, we receive the name of a city and return the current time there. If server
113113
receives an empty message, the connection is closed.

0 commit comments

Comments
 (0)