





1) Introduction









In order to use Rest Assured in your Maven project add this dependency:









2) Rest Assured GET examples





As a nice beginning I suggest to test ip.jsontest.com . This endpoint prints your current IP address. Here is simple test case that looks pretty much like copy/paste from excellent getting started guide . Please note that you would most likely have to update partOfMyIp String.









Second endpoint - date.jsontest.com returns date in three formats. Dealing with a time in tests can be tricky (flaky) so I decided to assert only date in MM-dd-yyyy format.









There is also echo.jsontest.com/key/value/one/two endpoint that gets the values from URL.









Another endpoint - cookie.jsontest.com sets the cookie as response. Here is the test that asserts if the cookie was set.









The most fun you may get from headers.jsontest.com . This endpoint reads headers from your request and prints them in response. I decided to send XML with UTF-8 enconding and assert Content Type.









3) Rest Assured POST examples





Those were GET examples. Now we would use POST method and send some data. Please note that .queryParam() method has to be defined in given() section which is a little bit strange for me. I'd rather code that in when() section after providing url.





First endpoint - endpoint - md5.jsontest.com/?text=text takes your text and returns it together with calculated md5 checksum.









Final endpoint which I decided to test is validate.jsontest.com . It takes 'json' queryParam value and validates if it's parse-able (i.e. if it's correctly formatted json). Below is simple happy path:









And negative path:









As usual all code from this post (+1 extra test) and from my previous Rest Assured Post is available on my GitHub project





1) Introduction2) Rest Assured GET examples3) Rest Assured POST examples