Git Product home page Git Product logo

scriptcs-webapi's Introduction

scriptcs-webapi

Web API Script Pack

What is it?

Makes using ASP.NET Web API's self host with scriptcs easy as cake, much easier than [this] (https://github.com/scriptcs/scriptcs-samples/tree/master/webapihost) :)

Highlights:

  • Creates a pre-configured OWIN self host with the default routes already added.
  • Supports configuring the OWIN pipeline
  • Write your controllers as scripts
  • Automatically imports common web api namespaces for you.

Getting started with Web API using the pack

  • Create a new folder for your script i.e. c:\hellowebapi and change to it.
  • Install the Web API script pack scriptcs -install -pre ScriptCs.WebApi2
  • Create a start.csx and paste the code below
using System.Dynamic;

public class TestController : ApiController
{
	public dynamic Get() {
		dynamic obj = new ExpandoObject();
		obj.message = "Hello from Web Api";
		return obj;
	}
}

var webapi = Require<WebApi>();

var server = webapi.
	Configure(typeof(TestController)).
	UseJsonOnly().
	Start("http://localhost:8080");

Console.WriteLine("Listening...");
Console.ReadLine();
server.Dispose();
  • Running as admin type scriptcs start.csx -modules mono on Windows or scriptcs start.csx on Mac/Linux to launch the app.
  • Open a browser to "http://localhost:8080/api/test";
  • That's it, your API is up!

Customizing

You can configure the OWIN host by passing in an Action<IAppBuilder> to the Configure method

var server = webapi.
	Configure(
		typeof(TestController),
		builder=> {
		  builder.Use<MyMiddleware>();
		}
	).
	Start("http://localhost:8080");

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.