# restful-api-demo **Repository Path**: gin-devops/restful-api-demo ## Basic Information - **Project Name**: restful-api-demo - **Description**: restful-api-demo - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2023-09-07 - **Last Updated**: 2023-09-08 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 实战-用Gin框架开发RESTful API ## 1.项目结构 ```shell $ tree restful-api-demo/ restful-api-demo/ ├── config # 配置文件(mysql配置 ip 端口 用户名 密码,不能写死到代码中) ├── controller # CLD:服务入口,负责处理路由、参数校验、请求转发 ├─ db # 封装GROM连接数据库和初始化操作 ├── main.go # 项目启动入口 ├── model # 模型(定义表结构) ``` ## 2.API接口实现 |接口|API地址|请求方式|是否实现| |-----|----------|--------|------| |注册用户|http://127.0.0.1:8888/api/v2/user/|POST|√| |删除用户|http://127.0.0.1:8888/api/v2/user/1|DELETE|√| |更新单个用户信息|http://127.0.0.1:8888/api/v2/user/2|PUT|√| |查询所有用户|http://127.0.0.1:8888/api/v2/user/|GET|√| |查询单个用户|http://127.0.0.1:8888/api/v2/user/2|GET|√| ### 2.1 注册用户 ```shell curl -X POST \ http://127.0.0.1:8888/api/v2/user/ \ -H 'Content-Type: application/x-www-form-urlencoded' \ -d 'name=hujianli2&phone=13262662212' ``` ### 2.2 删除用户 ```shell curl -X DELETE \ http://127.0.0.1:8888/api/v2/user/1 \ -H 'Content-Type: application/x-www-form-urlencoded' \ -d 'name=hujianli&phone=13262662216' ``` ### 2.3 更新单个用户信息 ```shell curl -X PUT \ http://127.0.0.1:8888/api/v2/user/2 \ -H 'Content-Type: application/x-www-form-urlencoded' \ -d 'name=hujianli1&phone=13262662216' ``` ### 2.4 查询所有用户 ```shell curl -X GET \ http://127.0.0.1:8888/api/v2/user/ ``` ### 2.5 查询单个用户 ```shell curl -X GET \ http://127.0.0.1:8888/api/v2/user/2 ```