> On Jun 5, 2016, at 12:51 AM, Chris Bui <christopher.d....@gmail.com> wrote: > > Here's what I'm trying to do: > > I have a REST API at work written in another language and I'd like to be able > to hit it with requests with lots of different combinations of parameters. My > second goal is to be able to verify that the data coming back in json > conforms to some schema. Essentially, if the value at a certain key is of a > certain type. I did some research and thought that contracts were perfect for > me. Am I correct about this? > > I started by trying to create a flat-named-contract that checks if the first > char of a string is a '/', like for a relative url or file path. I can define > the contract, but the generation aspect has been a wall for me. > > Could somebody give me an example?
1. You have exposed a gap in our Guide-level documentation. 2. Robby’s answer ought to help. 3. But let me add something that worked for me recently when I taught a Sw Dev course and the students voted to use JSON as the data exchange language. Say we agree that our components send/receive JSON arrays of length 3 with a string in position 0 followed by two natural numbers. Here is what I’d write in a DSL called redex (for modeling languages in general); #lang racket (require redex json) (define-language Triples ;; tagged JSON arrays of length 3 (e ::= [t n n]) (n ::= natural) (t ::= "nw" "ne" "sw" "se")) (redex-check Triples e (write-json (term e)) #:attempts 20) Run the above in DrRacket to see what it writes. You can also slap type systems at Triples to enforce additional invariants and Redex can — to some extent — generate things that satisfy the type system. For my course project (distributed game) I found this helpful (though also not completely satisfying). — Matthias -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.