{"id":41340164,"url":"https://github.com/farseer-go/webapi","last_synced_at":"2026-01-23T06:48:13.351Z","repository":{"id":58752706,"uuid":"529862721","full_name":"farseer-go/webapi","owner":"farseer-go","description":"用于快速构建api服务，带来极简、优雅的开发体验。编写api服务时，不需要使用httpRequest、httpResponse等数据结构。","archived":false,"fork":false,"pushed_at":"2025-09-29T15:18:15.000Z","size":330,"stargazers_count":76,"open_issues_count":2,"forks_count":3,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-29T16:16:20.593Z","etag":null,"topics":["action","api","controller","model","mvc","webapi"],"latest_commit_sha":null,"homepage":"https://farseer-go.gitee.io/","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/farseer-go.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2022-08-28T12:57:00.000Z","updated_at":"2025-09-29T15:18:19.000Z","dependencies_parsed_at":"2024-01-20T09:03:11.629Z","dependency_job_id":"1c2c2278-ebea-4b06-b633-d8dba53a786f","html_url":"https://github.com/farseer-go/webapi","commit_stats":{"total_commits":126,"total_committers":2,"mean_commits":63.0,"dds":0.007936507936507908,"last_synced_commit":"81aec74a159a69f60ffff12635a3e0393d19d51b"},"previous_names":[],"tags_count":41,"template":false,"template_full_name":null,"purl":"pkg:github/farseer-go/webapi","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/farseer-go%2Fwebapi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/farseer-go%2Fwebapi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/farseer-go%2Fwebapi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/farseer-go%2Fwebapi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/farseer-go","download_url":"https://codeload.github.com/farseer-go/webapi/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/farseer-go%2Fwebapi/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28682262,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-23T05:48:07.525Z","status":"ssl_error","status_checked_at":"2026-01-23T05:48:07.129Z","response_time":59,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["action","api","controller","model","mvc","webapi"],"created_at":"2026-01-23T06:48:12.223Z","updated_at":"2026-01-23T06:48:13.337Z","avatar_url":"https://github.com/farseer-go.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# webapi 概述\n\u003e 包：`\"github.com/farseer-go/webapi\"`\n\u003e \n\u003e 模块：`webapi.Module`\n\n\n- `Document`\n  - [English](https://farseer-go.github.io/doc/#/en-us/)\n  - [中文](https://farseer-go.github.io/doc/)\n  - [English](https://farseer-go.github.io/doc/#/en-us/)\n- Source\n  - [github](https://github.com/farseer-go/fs)\n\n\n![](https://img.shields.io/github/stars/farseer-go?style=social)\n![](https://img.shields.io/github/license/farseer-go/webapi)\n![](https://img.shields.io/github/go-mod/go-version/farseer-go/webapi)\n![](https://img.shields.io/github/v/release/farseer-go/webapi)\n[![codecov](https://img.shields.io/codecov/c/github/farseer-go/webapi)](https://codecov.io/gh/farseer-go/webapi)\n![](https://img.shields.io/github/languages/code-size/farseer-go/webapi)\n[![Build](https://github.com/farseer-go/webapi/actions/workflows/test.yml/badge.svg)](https://github.com/farseer-go/webapi/actions/workflows/test.yml)\n![](https://goreportcard.com/badge/github.com/farseer-go/webapi)\n\n\u003e 用于快速构建api服务，带来极简、优雅的开发体验。编写api服务时，不需要使用httpRequest、httpResponse等数据结构。\n\nwebapi使用了中间件的管道模型编写，让我们加入非业务逻辑时非常简单。\n\n包含两种风格来提供API服务：\n- `MinimalApi`：动态API风格（直接绑定到逻辑层）\n- `Mvc`：Controller、Action风格\n\n\u003e 使用minimalApi时，甚至不需要UI层来提供API服务。\n\n## webapi有哪些功能\n- 支持中间件\n- 入参、出参隐式绑定\n- 支持静态目录绑定\n- ActionFilter过虑器\n- ActionResult抽象结果\n- Area区域设置\n- MinimalApi模式\n- Mvc模式\n    - HttpContext上下文\n    - Header隐式绑定\n\n大部份情况下，除了main需要配置webapi路由外，在你的api handle中就是一个普通的func函数，不需要依赖webapi组件。webapi会根据`func函数`的`出入参`来`隐式绑定数据`。\n\n```go\nfunc main() {\n\tfs.Initialize[webapi.Module](\"FOPS\")\n\twebapi.RegisterPOST(\"/mini/hello1\", Hello1)\n\twebapi.RegisterPOST(\"/mini/hello3\", Hello3, \"pageSize\", \"pageIndex\")\n\twebapi.Run()\n}\n\n// 使用结构（DTO）来接收入参\n// 返回string\nfunc Hello1(req pageSizeRequest) string {\n\treturn fmt.Sprintf(\"hello world pageSize=%d，pageIndex=%d\", req.PageSize, req.PageIndex)\n}\n\n// 使用基础参数来接收入参\n// 返回pageSizeRequest结构（会自动转成json)\nfunc Hello3(pageSize int, pageIndex int) pageSizeRequest {\n    return pageSizeRequest{\n        PageSize:  pageSize,\n        PageIndex: pageIndex,\n    }\n}\n\n// 也可以定义一个结构，用于接收参数\ntype pageSizeRequest struct {\n    PageSize  int\n    PageIndex int\n}\n```\n函数中，`出入参都会自动绑定数据`\n\n\u003e 如果是`application/json`，则会自动被反序列化成model，如果是`x-www-form-urlencoded`，则会将每一项的key/value匹配到model字段中\n\n可以看到，整个过程，`不需要`做`json序列化`、`httpRequest`、`httpResponse`的操作。","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffarseer-go%2Fwebapi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffarseer-go%2Fwebapi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffarseer-go%2Fwebapi/lists"}