Skip to content

Commit

Permalink
Update ctx.md
Browse files Browse the repository at this point in the history
reformat queries docu
  • Loading branch information
ReneWerner87 authored Jun 19, 2023
1 parent f86423d commit fa5935b
Showing 1 changed file with 30 additions and 30 deletions.
60 changes: 30 additions & 30 deletions docs/api/ctx.md
Original file line number Diff line number Diff line change
Expand Up @@ -1067,33 +1067,6 @@ app.Get("/", func(c *fiber.Ctx) error {
})
```
## Query
This property is an object containing a property for each query string parameter in the route, you could pass an optional default value that will be returned if the query key does not exist.
:::info
If there is **no** query string, it returns an **empty string**.
:::
```go title="Signature"
func (c *Ctx) Query(key string, defaultValue ...string) string
```
```go title="Example"
// GET http://example.com/?order=desc&brand=nike

app.Get("/", func(c *fiber.Ctx) error {
c.Query("order") // "desc"
c.Query("brand") // "nike"
c.Query("empty", "nike") // "nike"

// ...
})
```
> _Returned value is only valid within the handler. Do not store any references.
> Make copies or use the_ [_**`Immutable`**_](ctx.md) _setting instead._ [_Read more..._](../#zero-allocation)
## Queries
Queries is a function that returns an object containing a property for each query string parameter in the route.
Expand Down Expand Up @@ -1129,9 +1102,9 @@ app.Get("/", func (c *fiber.Ctx) error {

app.Get("/", func(c *fiber.Ctx) error {
m := c.Queries()
m["list_a"] // "3"
m["list_b[]"] // "3"
m["list_c"] // "1,2,3"
m["list_a"] // "3"
m["list_b[]"] // "3"
m["list_c"] // "1,2,3"
})
```
Expand All @@ -1158,6 +1131,33 @@ app.Get("/", func(c *fiber.Ctx) error {
})
```
## Query
This property is an object containing a property for each query string parameter in the route, you could pass an optional default value that will be returned if the query key does not exist.
:::info
If there is **no** query string, it returns an **empty string**.
:::
```go title="Signature"
func (c *Ctx) Query(key string, defaultValue ...string) string
```
```go title="Example"
// GET http://example.com/?order=desc&brand=nike

app.Get("/", func(c *fiber.Ctx) error {
c.Query("order") // "desc"
c.Query("brand") // "nike"
c.Query("empty", "nike") // "nike"

// ...
})
```
> _Returned value is only valid within the handler. Do not store any references.
> Make copies or use the_ [_**`Immutable`**_](ctx.md) _setting instead._ [_Read more..._](../#zero-allocation)
## QueryBool
This property is an object containing a property for each query boolean parameter in the route, you could pass an optional default value that will be returned if the query key does not exist.
Expand Down

0 comments on commit fa5935b

Please sign in to comment.