Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

All other languages #10

Merged
merged 28 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions node/hello/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Node.js Hello Function

Welcome to your new Node.js Hello function! The function code can be found in [`index.js`](./index.js). This function will respond to incoming HTTP GET and POST requests. This template will simply respond will "Hello, World!".

## Local execution

After executing `npm install`, you can run this function locally by executing `npm run local`.

## Testing

This function project includes a [unit test](./test/unit.js) and an [integration test](./test/integration.js). All `.js` files in the test directory are run.

```console
npm test
```
29 changes: 29 additions & 0 deletions node/hello/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* Your Node function! This is a template function that simply prints
* 'Hello, World!' to the caller, and returns an error if the incoming request
* is something other than an HTTP POST or GET.
*
* In can be invoked with 'func invoke'
* It can be tested with 'npm test'
*
* @param {Context} context a context object.
* @param {object} context.body the request body if any
* @param {object} context.query the query string deserialized as an object, if any
* @param {object} context.log logging object with methods for 'info', 'warn', 'error', etc.
* @param {object} context.headers the HTTP request headers
* @param {string} context.method the HTTP request method
* @param {string} context.httpVersion the HTTP protocol version
* See: https://github.com/knative/func/blob/main/docs/function-developers/nodejs.md#the-context-object
*/
const handle = async (context, body) => {
console.log("Recieved request!") // printed on server
// If the request is an HTTP GET/POST
if (context.method === 'POST' || context.method === 'GET'){
return { statusMessage: "Hello, World!"} // send to client
} else {
return { statusCode: 405, statusMessage: 'Method not allowed' };
}
}

// Export the function
module.exports = { handle };
Loading
Loading