kore

Kore is a web application platform for writing scalable, concurrent web based processes in C or Python.
Commits | Files | Refs | README | LICENSE | git clone https://git.kore.io/kore.git

README.md (1852B)



      1 This example demonstrates how you can use the JSON-RPC module in your
      2 application.
      3 
      4 Note that the module depends upon the third-party library `yajl` (Yet Another
      5 JSON library) to parse and produce messages.
      6 
      7 As for the `yajl_json` example, conf/build.conf shows how to link to the
      8 library.
      9 
     10 This example needs kore having been compiled with `JSONRPC` (and so `HTTP`)
     11 activated.
     12 
     13 Run:
     14 ```
     15 	$ kodev run
     16 ```
     17 
     18 Test:
     19 ```
     20 	$ curl -i -k \
     21 	    -d '{"id":1,"jsonrpc":"2.0","method":"echo","params":["Hello world"]}' \
     22 	    https://127.0.0.1:8888/v1
     23 ```
     24 The result should echo back the string at `params`: Hello world.
     25 
     26 Alternatively, if you have bats installed:
     27 ```
     28 	$ bats test/integ/jsonrpc.bats
     29 ```
     30 Will run a small test suite.
     31 
     32 
     33 The yajl repo is available @ https://github.com/lloyd/yajl
     34 
     35 
     36 JSONRPC Request Lifetime
     37 ------------------------
     38 
     39 Currently, one HTTP request will (in most cases) provoke one and only one
     40 response. Batch mode is not supported yet, neither is websocket.
     41 
     42 As such `jsonrpc\_error` and `jsonrpc\_result` do clean the request after call.
     43 
     44 If however you want to abort the processed request, like by returning
     45 `KORE\_RESULT\_ERROR`, after it having been read, you need to clean it by
     46 calling `jsonrpc\_destroy\_request`. Other than that you shouldn't think about
     47 this function.
     48 
     49 
     50 Message Handling Log
     51 --------------------
     52 
     53 The `jsonrpc\_request` keeps a log of messages with levels similar to those of
     54 syslog. Messages are added with jsonrpc_log().
     55 
     56 By default messages of the log are added to the data member of the error
     57 responses if at levels EMERG, ERROR, WARNING and NOTICE.
     58 
     59 If you don't want log messages to be outputted zero the log_levels flag of the
     60 jsonrpc_request.
     61 
     62 
     63 Formatting responses
     64 --------------------
     65 
     66 By default responses are not prettyfied. To do that set the appropriate flag in
     67 the jsonrpc_request structure.