REST API
This REST API sample will help you to understand how you can send events to BAM through the REST API.
Prerequisites
You need to have curl installed and available to the command line path. Curl can be downloaded from http://curl.haxx.se/download.html.
Sample Guide
1. Start the WSO2 BAM Server.
2. Go to $WSO2_BAM_HOME/samples/rest-api directory via console.
3. Execute the rest-api.sh script with the command: ./rest-api.sh (on *nix systems) or rest-api.bat (on Windows systems)
4. You will see self explanatory logs as the sample is executed.
5. Look at the rest-api.sh or rest-api.bat to take a look at the curl commands that are taking place.
Explanation of the HTTP Requests
The body of the HTTP POST requests will be formed using the files in the same directory.
- The sample will post stream definitions using listing 1 and listing 3 as the body of the POST request.
- The sample will post events to the respective stream definitions using listing 2 and listing 4 as the body of the POST request.
Listing 1 - Stream definition - stockquote.stream, version 1.0.2 (streamdefn1.json)
{ "name":"stockquote.stream", "version": "1.0.2", "nickName": "Stock Quote Information", "description": "Some Desc", "tags":["foo", "bar"], "metaData":[ { "name":"ipAdd", "type":"STRING" } ], "payloadData":[ { "name":"symbol", "type":"string" }, { "name":"price", "type":"double" }, { "name":"volume", "type":"int" }, { "name":"max", "type":"double" }, { "name":"min", "type":"double" } ] }
- Curl command for defining stream definition in listing 1.
curl -k --user admin:admin https://localhost:9443/datareceiver/1.0.0/streams/ --data @streamdefn1.json -H "Accept: application/json" -H "Content-type: application/json" -X POST
Listing 2 - Events for stream definition stockquote.stream, version 1.0.2 (events1.json)
[ { "payloadData" : ["IBM", 26.0, 848, 43.33, 2.3] , "metaData" : ["123.233.0.1"] , "timeStamp" : 1312345432 }, { "payloadData" : ["MSFT", 22.0, 233, 22.22, 4.3] , "metaData" : ["5.211.1.1"] } ]
- Curl command for posting the two events in listing 2.
curl -k --user admin:admin https://localhost:9443/datareceiver/1.0.0/stream/stockquote.stream/1.0.2/ --data @events1.json -H "Accept: application/json" -H "Content-type: application/json" -X POST
Listing 3 - Stream definition - stockquote.stream.2, version 2.0.0 (streamdefn2.json)
{ "name":"stockquote.stream.2", "version": "2.0.0", "nickName": "Stock Quote Information", "description": "Some Desc", "tags":["foo", "bar"], "metaData":[ { "name":"ipAdd", "type":"STRING" } ], "payloadData":[ { "name":"symbol", "type":"string" }, { "name":"price", "type":"double" }, { "name":"volume", "type":"int" }, { "name":"max", "type":"double" }, { "name":"min", "type":"double" } ], "correlationData": [ { "name":"activityId", "type":"string" } ] }
- Curl command for defining stream definition in listing 3.
curl -k --user admin:admin https://localhost:9443/datareceiver/1.0.0/streams/ --data @streamdefn2.json -H "Accept: application/json" -H "Content-type: application/json" -X POST
Listing 4 - Events for Stream Definition, stockquote.stream.2, version 2.0.0 (events2.json)
[ { "payloadData" : ["IBM", 26.0, 848, 43.33, 2.3] , "metaData" : ["123.233.0.1"] , "correlationData" : ["2213-2324-2ffs-2444"], "timeStamp" : 1312345432 }, { "payloadData" : ["MSFT", 22.0, 233, 22.22, 4.3] , "metaData" : ["5.211.1.1"], "correlationData" : ["1243-eeef-2969-3566"], } ]
- Curl command for posting the two events in listing 4.
curl -k --user admin:admin https://localhost:9443/datareceiver/1.0.0/stream/stockquote.stream.2/2.0.0 --data @events2.json -H "Accept: application/json" -H "Content-type: application/json" -X POST