Skip to content

Instantly share code, notes, and snippets.

@pedroreys
Created March 23, 2012 19:05
Show Gist options
  • Save pedroreys/2173894 to your computer and use it in GitHub Desktop.
Save pedroreys/2173894 to your computer and use it in GitHub Desktop.
WebAPIContrib Transitions
public interface IApiResource {
void SetLocation(ResourceLocation resourceLocation);
void SetTransitions(ResourceTransitions transitions);
}
public class Order : IApiResource {
public int Id { get; set; }
// other resource members ...
public void SetLocation(ResourceLocation resourceLocation) {
resourceLocation.SetInController<OrdersController>(x => x.Get(this.Id));
}
public void SetTransitions(ResourceTransitions transitions) {
transitions.Add<PaymentController>("pay", x => x.Post());
transitions.Add<OrderController>("cancel", x=> x.DeleteOrder());
transitions.Add("foo", new Uri("http://foobar.com"));
}
}
// With that I can have IApiResource aware formatters that would know what to do with the transitions and generate the links accordingly.
// How does this looks to you? Does it align with your idea of the link generation helpers?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment