Code Monkey home page Code Monkey logo

orleans.httpgateway.aspnetcore's Introduction

Orleans.HttpGateway.AspNetCore

a http gateway for Microsoft Orleans.

Build status

Installation

Install-Package Orleans.HttpGateway.AspNetCore

Configuring the gateway

Startup.cs

public void ConfigureService(IServiceCollection services)
{
    // add known grain interface assemblies
    Assembly grainInterfaceAssembly = GetGrainInterfacesAssembly();
    services.AddOrleansHttpGateway(c => c.AddAssemblies(grainInterfaceAssembly));

    // ensure IGrainFactory is registered in the service container
    services.AddSingleton<IGrainFactory>(GetGrainFactory());
}

public void Configure(IApplicationBuilder app)
{
    // register the middleware in the application
    // note: the middleware internally uses Microsoft.AspNetCore.Routing
    // default route is: "{grainInterface}/{grainId}/{grainMethod}"
    app.UseOrleansHttpGateway();
}

IMPORTANT: Please note that ALL grains are accessible with this gateway, it is adviceable to not publicly expose the endpoint and use any of the default methods to securing your web app

Calling grains with http client

Grainmethods can be invoked using the following url format

http://your.aspnet.url/{grainInterface}/{grainId}/{grainMethod}

example: http://localhost:5000/Orleans.HttpGateway.AspNetCore.Tests.ITestGrain3/6/GetObjectWith2Parameters?one=1&two=okay

Providing method parameters

given the following grain interface:

public interface ITestGrain : IGrainWithStringKey
{
    Task<int> TestGrainMethod(string p1, bool p2, string[]p3);
}

parameters can be supplied by QueryParameters for GET requests, e.g. ?p1=one&p2=true&p3=[a,b,c]

complex parameters can also be provided in the request body using PUT or POST, names of the root elements must match the variable names in the GrainInterface and contenttype must be application/json:

{
    "p1":"one",
    "p2":true,
    "p3": ["a","b","c"]
}

note: not supplied values will default to null in the resulting grain call

Using Compound Grain Keys

Compound keys can be provided, seperated with a , e.g for an IGrainWithIntegerCompoundKey: http://localhost:5000/Orleans.HttpGateway.AspNetCore.Tests.ITestGrain3/1234,myStringkey/GetObjectWith2Parameters?one=1&two=okay

Acknowledgements

this project uses ObjectMethodExecutor from https://github.com/aspnet/Common/tree/dev/shared/Microsoft.Extensions.ObjectMethodExecutor.Sources

orleans.httpgateway.aspnetcore's People

Contributors

rikbosch avatar ericgla avatar

Watchers

James Cloos avatar  avatar

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.