Skip to content

Commit e1926bc

Browse files
committed
v0.12.0
1 parent 6497891 commit e1926bc

File tree

9 files changed

+37
-26
lines changed

9 files changed

+37
-26
lines changed

examples/3-working-with-json/gleam.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ wisp = { path = "../.." }
99
gleam_json = "~> 0.6"
1010
gleam_erlang = "~> 0.23"
1111
mist = "~> 0.14"
12+
gleam_http = "~> 3.5"
1213

1314
[dev-dependencies]
1415
gleeunit = "~> 1.0"

examples/5-using-a-database/gleam.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ gleam_json = "~> 0.6"
1010
tiny_database = { path = "../utilities/tiny_database" }
1111
gleam_erlang = "~> 0.23"
1212
mist = "~> 0.14"
13+
gleam_http = "~> 3.5"
1314

1415
[dev-dependencies]
1516
gleeunit = "~> 1.0"

examples/5-using-a-database/src/app/web/people.gleam

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import app/web.{type Context}
22
import gleam/dynamic.{type Dynamic}
33
import gleam/http.{Get, Post}
44
import gleam/json
5-
import gleam/map
5+
import gleam/dict
66
import gleam/result.{try}
77
import tiny_database
88
import wisp.{type Request, type Response}
@@ -41,12 +41,16 @@ pub fn list_people(ctx: Context) -> Response {
4141
use ids <- try(tiny_database.list(ctx.db))
4242

4343
// Convert the ids into a JSON array of objects.
44-
Ok(json.to_string_builder(json.object([
45-
#(
46-
"people",
47-
json.array(ids, fn(id) { json.object([#("id", json.string(id))]) }),
44+
Ok(
45+
json.to_string_builder(
46+
json.object([
47+
#(
48+
"people",
49+
json.array(ids, fn(id) { json.object([#("id", json.string(id))]) }),
50+
),
51+
]),
4852
),
49-
])))
53+
)
5054
}
5155

5256
case result {
@@ -88,11 +92,15 @@ pub fn read_person(ctx: Context, id: String) -> Response {
8892
use person <- try(read_from_database(ctx.db, id))
8993

9094
// Construct a JSON payload with the person's details.
91-
Ok(json.to_string_builder(json.object([
92-
#("id", json.string(id)),
93-
#("name", json.string(person.name)),
94-
#("favourite-colour", json.string(person.favourite_colour)),
95-
])))
95+
Ok(
96+
json.to_string_builder(
97+
json.object([
98+
#("id", json.string(id)),
99+
#("name", json.string(person.name)),
100+
#("favourite-colour", json.string(person.favourite_colour)),
101+
]),
102+
),
103+
)
96104
}
97105

98106
// Return an appropriate response.
@@ -123,9 +131,9 @@ pub fn save_to_database(
123131
person: Person,
124132
) -> Result(String, Nil) {
125133
// In a real application you might use a database client with some SQL here.
126-
// Instead we create a simple map and save that.
134+
// Instead we create a simple dict and save that.
127135
let data =
128-
map.from_list([
136+
dict.from_list([
129137
#("name", person.name),
130138
#("favourite-colour", person.favourite_colour),
131139
])
@@ -138,7 +146,7 @@ pub fn read_from_database(
138146
) -> Result(Person, Nil) {
139147
// In a real application you might use a database client with some SQL here.
140148
use data <- try(tiny_database.read(db, id))
141-
use name <- try(map.get(data, "name"))
142-
use favourite_colour <- try(map.get(data, "favourite-colour"))
149+
use name <- try(dict.get(data, "name"))
150+
use favourite_colour <- try(dict.get(data, "favourite-colour"))
143151
Ok(Person(name, favourite_colour))
144152
}

examples/5-using-a-database/test/app_test.gleam

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub fn main() {
1212
gleeunit.main()
1313
}
1414

15-
fn with_context(test: fn(Context) -> t) -> t {
15+
fn with_context(testcase: fn(Context) -> t) -> t {
1616
// Create a new database connection for this test
1717
use db <- tiny_database.with_connection(app.data_directory)
1818

@@ -21,7 +21,7 @@ fn with_context(test: fn(Context) -> t) -> t {
2121
let context = Context(db: db)
2222

2323
// Run the test with the context
24-
test(context)
24+
testcase(context)
2525
}
2626

2727
pub fn get_unknown_test() {

examples/6-serving-static-assets/gleam.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ gleam_stdlib = "~> 0.30"
88
wisp = { path = "../.." }
99
gleam_erlang = "~> 0.23"
1010
mist = "~> 0.14"
11+
gleam_http = "~> 3.5"
1112

1213
[dev-dependencies]
1314
gleeunit = "~> 1.0"

examples/6-serving-static-assets/src/app/router.gleam

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import wisp.{type Request, type Response}
22
import gleam/string_builder
3-
import gleam/http
43
import app/web.{type Context}
54

65
const html = "<!DOCTYPE html>
@@ -18,6 +17,6 @@ const html = "<!DOCTYPE html>
1817
"
1918

2019
pub fn handle_request(req: Request, ctx: Context) -> Response {
21-
use req <- web.middleware(req, ctx)
20+
use _req <- web.middleware(req, ctx)
2221
wisp.html_response(string_builder.from_string(html), 200)
2322
}

examples/6-serving-static-assets/test/app_test.gleam

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ pub fn main() {
99
gleeunit.main()
1010
}
1111

12-
fn with_context(test: fn(Context) -> t) -> t {
12+
fn with_context(testcase: fn(Context) -> t) -> t {
1313
// Create the context to use in tests
1414
let context = Context(static_directory: app.static_directory())
1515

1616
// Run the test with the context
17-
test(context)
17+
testcase(context)
1818
}
1919

2020
pub fn get_home_page_test() {

examples/8-working-with-cookies/gleam.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ wisp = { path = "../.." }
99
gleam_crypto = "~> 1.0"
1010
gleam_erlang = "~> 0.23"
1111
mist = "~> 0.14"
12+
gleam_http = "~> 3.5"
1213

1314
[dev-dependencies]
1415
gleeunit = "~> 1.0"

examples/utilities/tiny_database/src/tiny_database.gleam

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import gleam/dynamic
33
import ids/nanoid
44
import gleam/json
55
import gleam/list
6-
import gleam/map.{type Map}
6+
import gleam/dict.{type Dict}
77
import simplifile
88

99
pub opaque type Connection {
@@ -41,13 +41,13 @@ pub fn list(connection: Connection) -> Result(List(String), Nil) {
4141

4242
pub fn insert(
4343
connection: Connection,
44-
values: Map(String, String),
44+
values: Dict(String, String),
4545
) -> Result(String, Nil) {
4646
let assert Ok(_) = simplifile.create_directory_all(connection.root)
4747
let id = nanoid.generate()
4848
let values =
4949
values
50-
|> map.to_list
50+
|> dict.to_list
5151
|> list.map(fn(pair) { #(pair.0, json.string(pair.1)) })
5252
let json = json.to_string(json.object(values))
5353
use _ <- result.try(
@@ -60,13 +60,13 @@ pub fn insert(
6060
pub fn read(
6161
connection: Connection,
6262
id: String,
63-
) -> Result(Map(String, String), Nil) {
63+
) -> Result(Dict(String, String), Nil) {
6464
use data <- result.try(
6565
simplifile.read(file_path(connection, id))
6666
|> result.nil_error,
6767
)
6868

69-
let decoder = dynamic.map(dynamic.string, dynamic.string)
69+
let decoder = dynamic.dict(dynamic.string, dynamic.string)
7070

7171
use data <- result.try(
7272
json.decode(data, decoder)

0 commit comments

Comments
 (0)