Netlify Functions - Using path as input to function

Hi team,

Newbie here. Not much experience with JS/Netlify/Web development. I’m creating a netlify function and would like to use part of the url as in. Example:

www.mysite.com/.netlify/functions/myfunction/employee_code

Is it possible to have such a function where ‘employee_code’ is take as a parameter/argument for the ‘myfunction’ function? I know Query String Parameters is one way, but wondering if the path can be used too? Any example would be greatly appreciated.

Thanks in advance!

There’s no built-in way. You’d have to setup a middleware using Express.js or something similar. If that’s not acceptable, query parameters is the only way to go.

Got it. Thanks! Any good guides on how to use query parameters?

No guide as such, but it’s fairly simple. Here’s an old repo of mine in which I had used it:

event.queryStringParameters is an object like:

{
  param1: 'foo',
  param2: 'bar'
}

You can choose to use object destructuring if needed