Skip to content

Commit aa3b4a7

Browse files
Add docs from gofiber/fiber@cbcb1ae
1 parent ac84f4c commit aa3b4a7

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

docs/core/api/ctx.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,37 @@ app.Get("/", func(c *fiber.Ctx) error {
4949
})
5050
```
5151

52+
Media-Type parameters are supported.
53+
54+
```go title="Example 3"
55+
// Accept: text/plain, application/json; version=1; foo=bar
56+
57+
app.Get("/", func(c *fiber.Ctx) error {
58+
// Extra parameters in the accept are ignored
59+
c.Accepts("text/plain;format=flowed") // "text/plain;format=flowed"
60+
61+
// An offer must contain all parameters present in the Accept type
62+
c.Accepts("application/json") // ""
63+
64+
// Parameter order and capitalization does not matter. Quotes on values are stripped.
65+
c.Accepts(`application/json;foo="bar";VERSION=1`) // "application/json;foo="bar";VERSION=1"
66+
})
67+
```
68+
69+
```go title="Example 4"
70+
// Accept: text/plain;format=flowed;q=0.9, text/plain
71+
// i.e., "I prefer text/plain;format=flowed less than other forms of text/plain"
72+
app.Get("/", func(c *fiber.Ctx) error {
73+
// Beware: the order in which offers are listed matters.
74+
// Although the client specified they prefer not to receive format=flowed,
75+
// the text/plain Accept matches with "text/plain;format=flowed" first, so it is returned.
76+
c.Accepts("text/plain;format=flowed", "text/plain") // "text/plain;format=flowed"
77+
78+
// Here, things behave as expected:
79+
c.Accepts("text/plain", "text/plain;format=flowed") // "text/plain"
80+
})
81+
```
82+
5283
Fiber provides similar functions for the other accept headers.
5384

5485
```go

0 commit comments

Comments
 (0)