在Ruby和PHP中有两个有趣的框架可用于构建API。
Ruby:葡萄 https://github.com/intridea/grape/wiki
Php:Frapi http://getfrapi.com/
有没有人知道.NET中的同等事业?
例如,在Grape中,您可以按如下方式创建ruby类:
class MyAPI < Grape::API
prefix 'api'
get 'hello' do
{:hello => 'world'}
end
end
允许您像这样制作HTTP请求:
GET /api/hello
{“hello”:”world”}
那很可爱。
修改
经过反思,似乎WCF Http Rest服务可能与Frappi和Grape最相似,这让我的问题有些愚蠢。但我仍然希望收集一些具有工具的项目,甚至是一些专门用于创建API的框架。
Sprache,(下面回答)似乎非常有趣。
答案 0 :(得分:1)
这是一篇关于外部特定领域语言的好文章:
http://nblumhardt.com/2010/01/building-an-external-dsl-in-c/
这是文章中讨论的工具, Sprache :
http://code.google.com/p/sprache/
答案 1 :(得分:1)
取决于您想要做什么。您可以通过JSON or XML HTTP web service using WCF公开您的API。您还可以通过ASP.Net MVC公开类似控制器/操作Rails的API。
答案 2 :(得分:1)
Kayak是一款轻量级服务器。它让你轻松创建这些路线和响应:
https://github.com/kayak/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();
}
}
}