Manually Trigger Netlify Serverless Functions Locally

Jason Lengstorf
InstructorJason Lengstorf
Share this video with your friends

Social Share Links

Send Tweet
Published 4 years ago
Updated 4 years ago

There are a few ways you can run Netlify serverless functions while you are developing them.

You can:

  • Navigate to the directory under the /.netlify/functions/ path
  • Curl them using the full URL
  • Use an app like Postman

Instructor: [0:00] To test our serverless function, we can head up to the top here, and we'll see our live site. If we open this in another tab, we can see the site. It's doing what we expect. Again, nothing is persisting. If we refresh the page, we can see that none of our boop counts changed or stuck around, but we can access our serverless function right here in the browser.

[0:22] Again, all functions are going to live at .netlify/functions and then the name of our function without the .js, so in this case, Hello World, and we see Hello Egghead.

[0:36] That's not the only way that we can test these. We can also test these from the command line. If I want to run curl, and I can send a git header and the name of the function can run that and we see that we get back Hello Egghead.

[0:48] I can also use something like Postman. Let's open up Postman. Postman, if you're not familiar with it, is a way to quickly send different types of requests to different URLs to test things out. It's really nice when you're working with complicated requests.

[1:04] I'm going to grab this URL here, come in and paste it right into Postman. I'm going to send that. Now we can see our request here as well. If we needed to send headers, authorization, things like that, this can get much more useful, like I said. In this case, it's probably a little bit overkill. Later on, as you get deeper into serverless functions, this can be a really handy tool.