Giter VIP home page Giter VIP logo

Comments (4)

MadJlzz avatar MadJlzz commented on July 28, 2024 2

Indeed, it's missing documentation on how to call a function when the type is not http.
It's quite straightforward though. After some experiments, with a payload that looks like (for a function of type event):

{
    "eventId": "test",
    "timestamp": "2018-04-09T07:56:12.975Z",
    "eventType": "google.pubsub.topic.publish",
    "resource": "my-app",
    "data": {
        "data": "dGhpcyBpcyBkYXRhIG5vb2I=",
        "attributes": {
            "app": "my-app",
            "version": "1.0.0"
        }
  }
}

it returns

{'data': 'dGhpcyBpcyBkYXRhIG5vb2I=', 'attributes': {'app': 'my-app', 'version': '1.0.0'}}
{event_id: test, timestamp: 2018-04-09T07:56:12.975Z, event_type: google.pubsub.topic.publish, resource: my-app}

by doing simply print(event) and print(context)

with a function runned with:
functions-framework --target=<name_of_function_to_run> --signature-type=event

Please note that I may have found mismatch with the documentation here.

For example, you have to pass eventId and not event_id for the param to be correctly passed.

Hope this helps and available for PR if needed 😃

from functions-framework-python.

di avatar di commented on July 28, 2024

Thanks for the issue. There are some examples in #23 but ultimately this is blocked on that issue -- the "correct" way would be with the emulator.

from functions-framework-python.

origliante avatar origliante commented on July 28, 2024

You're welcome, thanks for pointing me there, I'm leaving a quick example here for people stumbling upon the issue
If you are running:

functions-framework --signature-type=event

This is the way to send an event to the server:
$ curl -d '{"data": {"hi": "there"}}' -X POST -H "Content-Type: application/json" http://localhost:8080

from functions-framework-python.

grayside avatar grayside commented on July 28, 2024

Perhaps linking to https://cloud.google.com/functions/docs/running/calling#background_functions would be useful?

from functions-framework-python.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.