Skip to content
garfield.moore edited this page Mar 17, 2015 · 4 revisions

Configuring Requests


Boomerang supports all HTTP verbs. You can configure these using Boomerangs simple fluent interface. The first thing you need to do is create an instance of Boomerang;

var host = Host.Boomerang.Create(
	    x => x.AtAddress("http://localhost:5100")
        );

Now your ready to configure requests on the host. Examples of using the interface is below;

GET

The below code configures will return a OK response with a body of 'Coffee' for a request to http://localhost:5100/api/menu

host.Get("api/menu/items/123").Returns("Coffee", 200);

Post

The below code will return a Created response with a body of Mocha for a request to the relative address api/menu/items/123

host.Post("api/menu/items/123").Returns("Mocha", 201);

Put

            host.Put("api/menu/items/123").Returns("Mocha", 201);

Delete

            host.Delete("api/menu/items/123").Returns("Mocha", 202);

Request

All other verbs are supported via the general Request method. For example, the below code configures a Trace request;

                host.Request("api/menu/items", "TRACE").Returns("", 200);

The second parameter defines the Http verb the request is configuring.

If you configure these several times you might consider creating you own extension method as below;

   public static IRequestHandler Trace(this IBoomerang host, string relativeUrl)
    {
        return host.Request(relativeUrl, "TRACE");
    }

Now you can simply use this extension method whereever you want to configure a Trace request;

   host.Trace("api/menu/items").Returns("Trace", 200);
Clone this wiki locally