Fiber: How can I get the request headers inside my handler 馃 ?

Created on 16 Jul 2020  路  4Comments  路  Source: gofiber/fiber

let's say that I need authorization headers, on express node.js I would do something like :

handler = (req, res, next) => {
  let BearerToken = req.headers.authorization.split(' ')[1];
  next();
}

How can I do this with go fiber?

馃 Question

All 4 comments

Thanks for opening your first issue here! 馃帀 Be sure to follow the issue template! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord

Hi @Badrouu17, Fiber almost uses the same API as Express. Please visit our docs for more information https://docs.gofiber.io/ctx#get

auth := strings.Split(ctx.Get("authorization"), " ")
if len(auth) > 1 {
  c.Locals("bearer", auth[1])
}
c.Next()

Hi @Badrouu17, Fiber almost uses the same API as Express. Please visit our docs for more information https://docs.gofiber.io/ctx#get

auth := strings.Split(ctx.Get("authorization"), " ")
if len(auth) > 1 {
  c.Locals("bearer", auth[1])
}
c.Next()

@Fenny. Thank you for responding quickly,
I think a better naming for this method would be "Headers()"
anyway keep up the good work guys 馃憦馃憦馃憦

No problem! Like I said before, our API is based on Expressjs. Minimalistic and simple for fast development http://expressjs.com/en/4x/api.html#req.get.

Feel free to close this issue if you don't have further questions :+1:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ahan picture ahan  路  3Comments

koddr picture koddr  路  4Comments

GrigoriyMikhalkin picture GrigoriyMikhalkin  路  4Comments

jeyraj picture jeyraj  路  4Comments

renanbastos93 picture renanbastos93  路  3Comments