• Some Web API Url Samples


    URI                               Verb     Description                                                                                    
     /api/tasks GET Gets the full list of all tasks;
    optionally specify a filter                  
    /api/tasks/123 GET Gets the details for a single task
    /api/tasks/123/status GET Gets just the status information
    for the specified task
    /api/tasks/123/status/456 PUT Updates just the status of
    the specified task
    /api/tasks/123/users DELETE Deletes all users from the
    specified task
    /api/tasks POST Creates a new task

    route map

    config.Routes.MapHttpRoute(
    name: "TaskStatusApiRoute",
    routeTemplate: "api/tasks/{taskId}/status/{statusId}",
    defaults: new {controller = "TaskStatus", statusId =
    RouteParameter.Optional});


    controller:

    public class TaskStatusController : ApiController
    {
    private readonly ISession _session;
    private readonly IStatusMapper _statusMapper;
    private readonly IHttpStatusFetcher _statusFetcher;
    private readonly IHttpTaskFetcher _taskFetcher;
    public TaskStatusController(
    IHttpTaskFetcher taskFetcher,
    ISession session,
    IStatusMapper statusMapper,
    IHttpStatusFetcher statusFetcher)
    {
    _taskFetcher = taskFetcher;
    _session = session;
    _statusMapper = statusMapper;
    _statusFetcher = statusFetcher;
    }
    
    public Status Get(long taskId) { var task = _taskFetcher.GetTask(taskId); return _statusMapper.CreateStatus(task.Status); }
    public void Put(long taskId, long statusId) { var task = _taskFetcher.GetTask(taskId); var status = _statusFetcher.GetStatus(statusId); task.Status = status; _session.Save(task); } }
  • 相关阅读:
    每日一题力扣222 完全二叉树节点的个数
    236 二叉树的最近公共祖先
    每日一题力扣122
    每日一题力扣 100 相同的树
    每日一题力扣617 合并二叉树
    每日一题力扣226
    每日一题力扣101 对称子树
    腾讯 qq 与 360 打架, 腾讯qq 无理
    决定把 blog 从 csdn.net 迁移到 cnblogs.com
    发现 google 网站管理员工具中给出的 javascript 代码是错误的
  • 原文地址:https://www.cnblogs.com/davidgu/p/4270159.html
Copyright © 2020-2023  润新知