Skip to content

Latest commit

 

History

History

function-sample-cloudevent

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Examples of Cloud Events with Spring via HTTP

Introduction

The current example uses spring-cloud-function framework as its core which allows users to only worry about functional aspects of their requirement while taking care-off non-functional aspects. For more information on Spring Cloud Function please visit our project page.

The example consists of a Spring boot configuration class DemoApplication which contains a sample function which you can interact with following via HTTP.

Given that SCF allows function to be exposed as REST endpoints, you can post cloud event to any of the functions by using function name as path (e.g., localhost:8080/<function_name>).

Here is an example of curl command posting a cloud event in binary-mode:

curl -w'\n' localhost:8080/hire \
 -H "ce-id: 0001" \
 -H "ce-specversion: 1.0" \
 -H "ce-type: hire" \
 -H "ce-source: spring.io/spring-event" \
 -H "Content-Type: application/json" \
 -d '{"firstName":"John", "lastName":"Doe"}' -i

And here is an example of curl command posting a cloud event in structured-mode:

curl -w'\n' localhost:8080/asString \
 -H "Content-Type: application/cloudevents+json" \
 -d '{
    "specversion" : "1.0",
    "type" : "org.springframework",
    "source" : "https://spring.io/",
    "id" : "A234-1234-1234",
    "datacontenttype" : "application/json",
    "data" : {
        "firstName" : "John",
        "lastName" : "Doe"
    }
}'