48 lines
1.7 KiB
Plaintext
48 lines
1.7 KiB
Plaintext
## 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 https://spring.io/projects/spring-cloud-function[project page].
|
|
|
|
The example consists of a Spring boot configuration class
|
|
https://github.com/spring-cloud/spring-cloud-function/blob/master/spring-cloud-function-samples/function-sample-cloudevent/src/main/java/io/spring/cloudevent/DemoApplication.java[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:
|
|
|
|
[source, text]
|
|
----
|
|
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:
|
|
|
|
[source, text]
|
|
----
|
|
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"
|
|
}
|
|
}'
|
|
----
|
|
|