vscode-azurefunctions icon indicating copy to clipboard operation
vscode-azurefunctions copied to clipboard

Customize default request body when executing function

Open oleksandr-ivanov-ah opened this issue 3 years ago • 10 comments
trafficstars

When clicking "Execute Function Now", the request body is set to { "name": "Azure" } by default.

Screenshot 2022-06-17 at 19 09 05

There is sample.dat in function directory but it looks like it doesn't read it. I checked the src code. It looks like tryGetSampleData have to read it, but it doesn't.

Is it possible to customize this default value?

oleksandr-ivanov-ah avatar Jun 17 '22 16:06 oleksandr-ivanov-ah

Currently it's not possible to customize the default value. However, this is a good idea and we'll see if we can include it in the next feature release.

alexweininger avatar Jun 23 '22 22:06 alexweininger

There is sample.dat in function directory but it looks like it doesn't read it. I checked the src code. It looks like tryGetSampleData have to read it, but it doesn't.

Just to clarify, this function gets the sample data from the template provider. The templates themselves have sample files associated to them including a sample.dat. We never intended to let users provide custom sample.dat files.

I think we would need to spend some time to design this feature. For example, Execute Function Now... can also be used for remote triggers. In those cases, would it make sense to use a sample.dat or should this be exclusively for local projects?

@oleksandr-ivanov-ah Where would you expect the sample.dat to live in your project?

  • Should it be in the root of the Functions project?
  • Should it be in the individual folder of each Function trigger?

The issue with option 1 is that we wouldn't know which custom sample data to use for each trigger. I think we could structure the sample.dat to be a JSON file that lives in the root, and the keys would be the trigger names that should be used as the custom default request bodies.

Issue with option 2 is that not all function runtimes separate the triggers into folders. I think that we could still enable this scenario, but fall back to option 1 if either:

  1. There is no sample.dat in the function's folder
  2. Functions aren't structured in such a way that they are in individual folders

nturinski avatar Aug 02 '22 23:08 nturinski

This feature request is now a candidate for our backlog. The community has 240 days to upvote the issue. If it receives 5 upvotes we will move it to our backlog. If not, we will close it. To learn more about how we handle feature requests, please see our documentation.

Happy Coding!

AzCode-Bot avatar Aug 10 '22 05:08 AzCode-Bot

Ah, I was similarly confused by sample.dat and assumed it was an error when "Enter request body" did not grab data from it. (This codebase does seem to reference sample.dat but perhaps I'm not following how it's using it). Is there a reason to include the generated sample.dat file in the function if developers cant really use it themselves? (i.e. could it be excluded for now so that it feels less like a bug.. I edited that file so many times!)

pamelafox avatar Sep 21 '22 23:09 pamelafox

This issue has become stale and is at risk of being closed. The community has 60 days to upvote the issue. If it receives 5 upvotes we will keep it open and take another look. If not, we will close it. To learn more about how we handle issues, please see our documentation.

Happy Coding!

AzCode-Bot avatar Feb 07 '23 05:02 AzCode-Bot

@nturinski i would prefer to have sample.data in function app root folder. Like this: Screenshot 2023-08-02 at 23 21 59

oleksandr-ivanov-ah avatar Aug 02 '23 21:08 oleksandr-ivanov-ah

I think json format is preferable: sample.json

oleksandr-ivanov-ah avatar Aug 02 '23 21:08 oleksandr-ivanov-ah