🧚 A practical web framework for Gleam

get_query

+29
+12
src/wisp.gleam
··· 718 718 /// 719 719 pub const set_header = response.set_header 720 720 721 + /// Parse the query parameters of a request into a list of key-value pairs. The 722 + /// `key_find` function in the `gleam/list` stdlib module may be useful for 723 + /// finding values in the list. 724 + /// 725 + /// Query parameter names do not have to be unique and so may appear multiple 726 + /// times in the list. 727 + /// 728 + pub fn get_query(request: Request) -> List(#(String, String)) { 729 + request.get_query(request) 730 + |> result.unwrap([]) 731 + } 732 + 721 733 /// This function overrides an incoming POST request with a method given in 722 734 /// the request's `_method` query paramerter. This is useful as web browsers 723 735 /// typically only support GET and POST requests, but our application may
+17
test/wisp_test.gleam
··· 981 981 out 982 982 |> should.equal(message) 983 983 } 984 + 985 + pub fn get_query_test() { 986 + testing.get("/wibble?wobble=1&wubble=2&wobble=3&wabble", []) 987 + |> wisp.get_query 988 + |> should.equal([ 989 + #("wobble", "1"), 990 + #("wubble", "2"), 991 + #("wobble", "3"), 992 + #("wabble", ""), 993 + ]) 994 + } 995 + 996 + pub fn get_query_no_query_test() { 997 + testing.get("/wibble", []) 998 + |> wisp.get_query 999 + |> should.equal([]) 1000 + }