前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >.NET 基金会项目介绍-Nancy

.NET 基金会项目介绍-Nancy

作者头像
newbe36524
发布2020-03-16 10:36:26
5530
发布2020-03-16 10:36:26
举报

Nancy 是属于 .Net 基金会的一个项目,本文将简要介绍该项目相关的信息。

中文介绍

中文介绍内容翻译自英文介绍,主要采用意译、如与原文存在出入,请以原文为准。

Nancy

Nancy 是一个轻量的,简洁的HTTP服务构建框架,能够支持运行于 .Net Framework/Core 以及 Mono。该框架的目标在保持平台无关的前提下,保持各个环节都拥有 super-duper-happy-path 的体验(极致畅爽的开发体验)。

Nancy 能够处理 DELETE, GET, HEAD, OPTIONS, POST, PUTPATCH 的请求。

其提供了一套简明优雅的 DSL 以便开发者能够稍微敲打几个字便能处理 HTTP 响应。这样开发者便可以将更多的时间应用于业务代码与核心程序。

以下便是一个简明扼要的 Hello 代码实例:

代码语言:javascript
复制
public class Module : NancyModule
{
    public Module()
    {
        Get("/greet/{name}", x => {
            return string.Concat("Hello ", x.name);
        });
    }
}

The super-duper-happy-path (极致畅爽的开发体验)

“super-duper-happy-path” (或称 SDHP) 是我们为体现 Nancy 框架的核心精神和创建的短语,并且我们秉承着 “super-duper-happy-path” 的经验,在 API 开发中努力践行。

尽管很难具体的定义这种精神是什么,毕竟这是一个非常情绪化的术语,不过其基本的奥义如下:

  • “It just works”(轻松启动) - 开发者可以轻松的用起来,而无需要将复杂的内容混合在一起。想要添加一个新的模块?好的,没问题!它将会被自动发现并弃用;想要引入一个新的视图引擎?好的,没问题!所有的工作都已经准备好了您无需过多操心;想要为模块注入一个新的依赖项?好的,没问题!默认我们将会为您定位并注入它到您的模块,完全零配置。
  • “Easily customisable”(快乐扩展) - 尽管已经能够轻松启动,但是如果需要进行自定义扩展也不应有任何障碍。比如想要自定义依赖注入容器?完全没问题!想要调整路由规则?完全没问题!通过框架的启动器机制,所有这些自定义都是小菜一碟。
  • “Low ceremony”(极致简洁) - 在您的程序中为了框架而写的 “Nancy 代码” 尽可能被保持最小。使用 Nancy 构建的应用程序中最为重要的部分应该是您的代码。我们的代码为您服务,为您编写精妙的应用程序而让路。您甚至完全可以在一篇推文(140个字符)中将你应用程序所需要编写的 Nancy 代码全部包含其中。
  • “Low friction”(纵享丝滑) - 使用 Nancy 构建应用程序,我们将助您成功而非制造麻烦。尽管命名需要明确,配置量也被最小化,但其拥有的功能性和扩展性并不会打折,依旧强力,如您所需。

Above all, creating an application with Nancy should be a pleasure, and hopefully fun! But without sacrificing the power or extensibility that you may need as your application grows.

综上所述,采用 Nancy 构建一个应用程序将会是一件令人愉悦的乐事,完全不需要牺牲功能性和扩展性,轻松构建您的应用程序。

Project Details

相关链接

笔者简评

在 .Net 中构建 HTTP 应用程序的传统方法皆是围绕微软传统框架: WebForms 、 MVC 、 WebAPI 等等。而 Nancy 作为一个独立的开源项目已经存在很长时间,并且一直在活跃中。

如果您正想查找一个轻量型优秀 HTTP 应用程序构建框架,这回事一个不错的尝试。

英文介绍

Nancy

Nancy is a lightweight, low-ceremony, framework for building HTTP based services on .NET Framework/Core and Mono. The goal of the framework is to stay out of the way as much as possible and provide a super-duper-happy-path to all interactions.

Nancy is designed to handle DELETE, GET, HEAD, OPTIONS, POST, PUT and PATCH requests and provides a simple, elegant, Domain Specific Language (DSL) for returning a response with just a couple of keystrokes, leaving you with more time to focus on the important bits..

your code and your application.

Write your application

代码语言:javascript
复制
public class Module : NancyModule
{
    public Module()
    {
        Get("/greet/{name}", x => {
            return string.Concat("Hello ", x.name);
        });
    }
}
The super-duper-happy-path

The “super-duper-happy-path” (or SDHP if you’re ‘down with the kids’ ;-)) is a phrase we coined to describe the ethos of Nancy; and providing the “super-duper-happy-path” experience is something we strive for in all of our APIs.

While it’s hard to pin down exactly what it is, it’s a very emotive term after all, but the basic ideas behind it are:

  • “It just works” - you should be able to pick things up and use them without any mucking about. Added a new module? That’s automatically discovered for you. Brought in a new View Engine? All wired up and ready to go without you having to do anything else. Even if you add a new dependency to your module, by default we’ll locate that and inject it for you - no configuration required.
  • “Easily customisable” - even though “it just works”, there shouldn’t be any barriers that get in the way of customisation should you want to work the way you want to work with the components that you want to use. Want to use another container? No problem! Want to tweak the way routes are selected? Go ahead! Through our bootstrapper approach all of these things should be a piece of cake.
  • “Low ceremony” - the amount of “Nancy code” you should need in your application should be minimal. The important part of any Nancy application is your code - our code should get out of your way and let you get on with building awesome applications. As a testament to this it’s actually possible to fit a functional Nancy application into a single Tweet :-)
  • “Low friction” - when building software with Nancy the APIs should help you get where you want to go, rather than getting in your way. Naming should be obvious, required configuration should be minimal, but power and extensibility should still be there when you need it.

Above all, creating an application with Nancy should be a pleasure, and hopefully fun! But without sacrificing the power or extensibility that you may need as your application grows.

Project Details
Quicklinks

以上《英文介绍》摘录自 .NET Foundation 的项目介绍 。原文受原项目许可证保护。

其他项目地址

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2020-01-092,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 中文介绍
    • Nancy
      • The super-duper-happy-path (极致畅爽的开发体验)
        • Project Details
          • 相关链接
      • 笔者简评
      • 英文介绍
        • Nancy
          • The super-duper-happy-path
          • Project Details
          • Quicklinks
      • 其他项目地址
      相关产品与服务
      容器服务
      腾讯云容器服务(Tencent Kubernetes Engine, TKE)基于原生 kubernetes 提供以容器为核心的、高度可扩展的高性能容器管理服务,覆盖 Serverless、边缘计算、分布式云等多种业务部署场景,业内首创单个集群兼容多种计算节点的容器资源管理模式。同时产品作为云原生 Finops 领先布道者,主导开源项目Crane,全面助力客户实现资源优化、成本控制。
      领券
      问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档