Some Web API Url Samples

URI                               Verb     Description                                                                                    
 /api/tasksGETGets the full list of all tasks;
optionally specify a filter                  
/api/tasks/123GETGets the details for a single task
/api/tasks/123/statusGETGets just the status information
for the specified task
/api/tasks/123/status/456PUTUpdates just the status of
the specified task
/api/tasks/123/usersDELETEDeletes all users from the
specified task
/api/tasksPOSTCreates a new task


route map

name: "TaskStatusApiRoute",
routeTemplate: "api/tasks/{taskId}/status/{statusId}",
defaults: new {controller = "TaskStatus", statusId =


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); } }



评论将由博主筛选后显示,对所有人可见 | 还能输入1000个字符 “速评一下”
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页