此前我一直觉得java系的spring boot写起REST风格的API来非常灵活,直接在controller、action上就可以进行设置路由,如:

@Controller
@RequestMapping(value="/api")
public class HelloWorldController {

@ResponseBody
@RequestMapping(value = "/helloworld", method = RequestMethod.GET)
public String hello(){//返回JSON
return "Hello World!";
}
}

因此赞叹不已,并以此作为JAVA系超过.NET系的证据之一。

其实,是我孤陋寡闻了,asp.net也可以的:

[HttpGet]
[Route("api/user/exists/{loginname}")]
public bool Exists(string loginname)
{
OrgUser user = this._accountService.GetUserListByLoginName(new UserRequest()
{
LoginName = loginname
}).FirstOrDefault();
return (user != null);
}

​有关asp.net​​ 提供API的文章,此前陆续有写过一些,来个总结:

​C# WebApi Get请求方式传递实体参数​

​mysql + Fluently NHibernate + WebAPI + Autofac​

​ASP.NET for WebApi​

​ASP.NET MVC 提供与访问 Web Api​