Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/317.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# NET的一些web API框架是什么?像弗拉皮或葡萄_C#_.net_Api_Frameworks - Fatal编程技术网

C# NET的一些web API框架是什么?像弗拉皮或葡萄

C# NET的一些web API框架是什么?像弗拉皮或葡萄,c#,.net,api,frameworks,C#,.net,Api,Frameworks,Ruby和PHP中有两个有趣的框架,它们提供了构建API的工具 鲁比:葡萄 Php:Frapi 有人知道在.NET中有类似的承诺吗 例如,在Grape中,您可以创建一个ruby类,如下所示: class MyAPI < Grape::API prefix 'api' get 'hello' do {:hello => 'world'} end end 那太好了 编辑 经过反思,似乎WCF Http Rest服务可能与Frappi和G

Ruby和PHP中有两个有趣的框架,它们提供了构建API的工具

鲁比:葡萄

Php:Frapi

有人知道在.NET中有类似的承诺吗

例如,在Grape中,您可以创建一个ruby类,如下所示:

class MyAPI < Grape::API
    prefix 'api'

    get 'hello' do
        {:hello => 'world'}
    end
end
那太好了


编辑


经过反思,似乎WCF Http Rest服务可能与Frappi和Grape最为相似,这让我的问题有点傻。但是我仍然希望能够收集到一些有工具的项目,甚至是一些特定于创建API的框架

Sprache(回答如下)似乎很有趣。

这里有一篇关于外部领域特定语言的好文章:

这是本文讨论的工具,Sprache:

取决于你到底想做什么。您可以通过以下方式公开您的API:。您还可以通过公开类似API的控制器/操作Rails。

Kayak是一种轻量级服务器。它让您可以轻松创建这些路由和响应:

从示例中可以看出:

using System;
using System.Collections.Generic;
using System.Net;
using System.Text;
using Kayak;

namespace KayakExamples
{
    class Simple
    {
        public static void Run()
        {
            var server = new DotNetServer();

            var pipe = server.Start();

            server.Host((env, respond, error) =>
                {
                    respond(new Tuple<string, IDictionary<string, IEnumerable<string>>, IEnumerable<object>>(
                            "200 OK",
                            new Dictionary<string, IEnumerable<string>>() 
                            {
                                { "Content-Type",  new string[] { "text/html" } }
                            },
                            new object[] { Encoding.ASCII.GetBytes("Hello world.") }
                        ));
                });

            Console.WriteLine("Listening on " + server.ListenEndPoint);
            Console.WriteLine("Press enter to exit.");
            Console.ReadLine();

            pipe.Dispose();
        }
    }
}
使用系统;
使用System.Collections.Generic;
Net系统;
使用系统文本;
使用皮艇;
名称空间Kayakes示例
{
简单类
{
公共静态无效运行()
{
var server=new DotNetServer();
var pipe=server.Start();
server.Host((环境、响应、错误)=>
{
响应(新元组)(
“200好”,
新字典()
{
{“内容类型”,新字符串[]{“text/html”}
},
新对象[]{Encoding.ASCII.GetBytes(“Hello world.”)}
));
});
Console.WriteLine(“监听”+server.listenedpoint);
控制台。WriteLine(“按enter键退出”);
Console.ReadLine();
管道处理();
}
}
}

这是一个有趣的项目,但它对解析不是有点特殊吗?这是一个好的开始,但我也在寻找一些抽象出REST服务创建的东西。ASP.Net不是一个与Grape完全一致的解决方案,但我认为RESTWCF是……ASP.Net可能不是,但ASP.NETMVC可能是。您可以通过某些操作创建一个控制器,并且您的视图可以是您的XML/JSON输出。对,但是如果您查看上面的示例,就不需要创建控制器或视图。它是类和方法定义的简单扩展,带有一些特殊的钩子。事实上,这个示例变得更加深入,可以非常快速地定义整个API。MVC很像Zend Framework或Ruby on Rails,但Grape和Frapi的不同之处在于它们为构建REST API提供了一个非常简洁的框架。我对WCF-REST几乎没有经验,但我认为这可能是所需要的全部。
using System;
using System.Collections.Generic;
using System.Net;
using System.Text;
using Kayak;

namespace KayakExamples
{
    class Simple
    {
        public static void Run()
        {
            var server = new DotNetServer();

            var pipe = server.Start();

            server.Host((env, respond, error) =>
                {
                    respond(new Tuple<string, IDictionary<string, IEnumerable<string>>, IEnumerable<object>>(
                            "200 OK",
                            new Dictionary<string, IEnumerable<string>>() 
                            {
                                { "Content-Type",  new string[] { "text/html" } }
                            },
                            new object[] { Encoding.ASCII.GetBytes("Hello world.") }
                        ));
                });

            Console.WriteLine("Listening on " + server.ListenEndPoint);
            Console.WriteLine("Press enter to exit.");
            Console.ReadLine();

            pipe.Dispose();
        }
    }
}