Skip to content

Fn Function Basics Write Up

Michael J Williams edited this page Oct 4, 2018 · 7 revisions

The following is a write up to replace the STDIN/STDOUT discussion in the Fn introduction. Once we get the wording right, we use that to update other documents and tutorials.

Old Wording

Writing a function for Fn is easy. You just create a small chunk of code that does the following:

  • Gets input via STDIN
  • Produces output to STDOUT
  • Logs any errors to STERR

Your code is deployed to an Fn server where it is staged and ready to go when a call is made for that function. For example, to create deploy an Fn function create a myfunc directory, change into it, and execute these commands:

New Wording

Writing a function for Fn is easy. You just create a small handler function that does the following:

  • Reads data passed in an HTTP request in the format specified by the content-type:. By default this is text/plain. (With the cli, use the --content-type to specify the content type.)
  • Returns the data in an HTTP response using the same content-type:.
  • Logs any errors to STERR

Note: See the tutorial for your language for an example of the function name used for that language.

Your code is deployed to an Fn server where it is staged and ready to go when that function is invoked. For example, to create deploy an Fn function create a myfunc directory, change into it, and execute these commands: