Skip to content

Commit

Permalink
[Update] README
Browse files Browse the repository at this point in the history
  • Loading branch information
stulzq committed Jun 11, 2019
1 parent 08158f1 commit 966ef25
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
55 changes: 54 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,62 @@ public void ConfigureServices(IServiceCollection services)

本快速入门 Demo 地址:[点我](/samples/Panda.DynamicWebApiSample)

## 2.更进一步

(1)要让类生成动态API需要满足两个条件,一个是该类**直接****间接**实现 `IDynamicWebApi`,同时该类**本身**或者**父类**或者**实现的接口**具有特性 `DynamicWebApi`

## 3.引用项目
(2)添加特性 `[NonDynamicWebApi]` 可使一个类或者一个方法不生成API,`[NonDynamicWebApi]` 具有最高的优先级。

(3)会对符合规则的动态API**类名**进行后缀的删除,如:我们快速入门的 `AppleAppService`,会被删除 AppService 后缀,这个规则是可以动态配置的。

(4)会自动添加API路由前缀,默认会为所有API添加 `api`前缀

(5)默认的HTTP动词为`POST`,可以理解为API的 Http Method。但可以通过 `HttpGet/HttpPost/HttpDelete `等等ASP.NET Core 内置特性来覆盖

(6)可以通过`HttpGet/HttpPost/HttpDelete `等内置特性来覆盖默认路由

(7)默认会根据你的方法名字来设置HTTP动词,如 CreateApple 或者 Create 生成的API动词为 `POST`,对照表如下,若命中(忽略大小写)对照表那么该API的名称中的这部分将会被省略,如 CreateApple 将会变成 Apple,如未在以下对照表中,将会使用默认动词 `POST`

| 方法名开头 | 动词 |
| ---------- | ------ |
| create | POST |
| add | POST |
| post | POST |
| get | GET |
| find | GET |
| fetch | GET |
| query | GET |
| update | PUT |
| put | PUT |
| delete | DELETE |
| remove | DELETE |

(8)强烈建议方法名称使用帕斯卡命名(PascalCase)规范,且使用以上对照表的动词。如:

添加苹果 -> Add/AddApple/Create/CreateApple

更新苹果 -> Update/UpdateApple

...

## 3.配置

所有的配置均在对象 `DynamicWebApiOptions` 中,说明如下:

| 属性名 | 是否必须 | 说明 |
| --------------------------- | -------- | --------------------------------------------------------- |
| ApiAssemblies || 要生成API的类所在的程序集(MVC框架需要扫描) |
| DefaultHttpVerb || 默认值:POST。默认HTTP动词 |
| DefaultAreaName || 默认值:空。Area 路由名称 |
| DefaultApiPreFix || 默认值:api。API路由前缀 |
| ApiRemovePostfixes || 默认值:AppService/ApplicationService。类名需要移除的后缀 |
| FormBodyBindingIgnoredTypes || 默认值:IFormFile。不通过MVC绑定到参数列表的类型。 |

## 4.疑难解答

若遇到问题,可使用 [Issues](https://github.com/dotnetauth/Panda.DynamicWebApi/issues) 进行提问。

## 5.引用项目说明

> 本项目直接或间接引用了以下项目
Expand Down
Binary file added assets/0F703DDD.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/Panda.DynamicWebApi/AppConsts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ static AppConsts()
{
HttpVerbs=new Dictionary<string, string>()
{
["Add"]="POST",
["create"]="POST",
["post"]="POST",

Expand Down

0 comments on commit 966ef25

Please sign in to comment.