ASP.NET 的API

1、只要action的名字等于HTTP请求动作的名称或action的名字是以http请求动作名称开头命名的都能匹配
2、POST请求用来做添加 PUT用来做修改 GET用来做查询 
3、默认约束基础类型的参数通过URL传递(int,string,double等)复合类型的参数通过请求体传递
特点:1、URL只能要体现要操作的资源名称
          2、对资的操作在http请求的动作上体现出来
          3、Post--添加  Get--查询   Put--修改  Delete--删除

满足以上三个特点的借口叫做 rest风格的接口 rest api

//创建一个API控制器(Controller) 
public class RoleController : ApiController
    {
        IRoleBll bll = new RoleBll();
//查询Role表里的全部数据
        public List<Role> Get()
        {
            List<Role> list = bll.Search(null);
            return list;
        }
//往Role表里添加数据
        public object Post(Role model)
        {
            string msg;
            bool isOK = bll.Add(model, out msg);
            return new { state=isOK};
        }
//通过ID修改Role表里的数据
        public object Put(int id,Role model)
        {
            string msg;
            model.ID = id;
            bool isOk = bll.Update(model, out msg);
            return new { state = isOk };
        }
//通过id查询Role里的某条数据
        public Role GetOne(int id)
        {
            Role model = bll.Search(id);
            return model;
        }
//删除
        public object Delete(int id)
        {
            string msg;
            bool isOk = bll.Delete(id, out msg);
            return new { state = isOk };
        }
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值