Skip to content

Instantly share code, notes, and snippets.

View beyond-code-github's full-sized avatar

Pete Smith beyond-code-github

View GitHub Profile
@beyond-code-github
beyond-code-github / HelloWorldModule.cs
Created September 22, 2013 16:45
Extended hello world module which will return some 'interesting' json
namespace OwinModulesHelloWorld
{
using Superscribe.Owin;
public class HelloWorldModule : SuperscribeOwinModule
{
public HelloWorldModule()
{
this.Get["/"] = _ => "Hello world - OWIN style";
@beyond-code-github
beyond-code-github / Startup.cs
Created September 22, 2013 16:38
Startup.cs for Owin Hello world including Json media type handler
namespace OwinModulesHelloWorld
{
using System.IO;
using Newtonsoft.Json;
using Owin;
using Superscribe.Owin;
public class Startup
{
public void Configuration(IAppBuilder app)
namespace OwinModulesHelloWorld
{
using Superscribe.Owin;
public class HelloWorldModule : SuperscribeOwinModule
{
public HelloWorldModule()
{
this.Get["/"] = _ => "Hello world - OWIN style";
}
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
<appSettings>
<add key="owin:HandleAllRequests" value="true" />
<add key="owin:SetCurrentDirectory" value="true" />
</appSettings>
namespace OwinModulesHelloWorld
{
using Owin;
using Superscribe.Owin;
public class Startup
{
public void Configuration(IAppBuilder app)
{
@beyond-code-github
beyond-code-github / Require.cs
Created September 20, 2013 19:08
Example of dependency injection using Require
this.Get["Products" / (ʃLong)"Id"] = _ =>
{
var service = _.Require<IProductsService>();
return service.Get(_.Parameters.Id);
};
this.Post["Products"] = _ =>
{
var service = _.Require<IProductsService>();
var product = _.Bind<Product>();
private static void RegisterServices(IKernel kernel)
{
kernel.Bind<IProductsService>().To<ProductsService>();
GlobalConfiguration.Configuration.DependencyResolver = new NinjectDependencyResolver(kernel);
}
@beyond-code-github
beyond-code-github / CreateResponse.cs
Created September 20, 2013 18:45
Post handler with create response
this.Post["Products"] = _ =>
{
var product = _.Bind<Product>();
// Save product
return _.Request.CreateResponse(
HttpStatusCode.Created,
new { Link = new { href = string.Format("http://api.localhost/products/{0}", product.Id) } });
};
@beyond-code-github
beyond-code-github / ModelBinding.cs
Last active December 23, 2015 13:28
Model binding and returning a custom status code
namespace WebApiModuleHelloWorld
{
using System.Net;
public class Product
{
public string Name { get; set; }
public double Price { get; set; }
}
@beyond-code-github
beyond-code-github / TimeDependantRoute.cs
Last active December 23, 2015 13:19
Time dependant insulting route behavior with Superscribe
namespace WebApiModuleHelloWorld
{
using System;
using Superscribe.Models;
public class HelloWorldModule : Superscribe.WebApi.Modules.SuperscribeModule
{
public HelloWorldModule()
{