Search code examples
rule-enginedurable-rules

How do you run the server to use/test the JSON format?


The Reference Manuak at https://github.com/jruizgit/rules/blob/master/docs/json/reference.md says that I can assert facts like this:

curl -H "content-type: application/json" -X POST -d '{"subject": "Tweety", "predicate": "eats", "object": "worms"}' http://localhost:5000/animal/facts

But how I run the server at port 5000? Does durable_rules comes with a built in HTTP Server?


Solution

  • thanks for asking the question. The JSON doc is outdated. durable_rules V2, no longer starts an http server (which gives you the flexibility to choose how you want to host your rulesets). You can provide a JSON document as follows:

    from durable.lang import *
    
    def callback(c):
        print('risk7 fraud detected')
    
    get_host().set_rulesets({ 'risk7': {
        'suspect': {
            'run': callback,
            'all': [
                {'first': {'t': 'purchase'}},
                {'second': {'$neq': {'location': {'first': 'location'}}}}
            ],
        }
    }})
    
    post('risk7', {'t': 'purchase', 'location': 'US'});
    post('risk7', {'t': 'purchase', 'location': 'CA'});