asp.net Web API HTTP PUT方法 [英] asp.net web API HTTP PUT method

查看:91
本文介绍了asp.net Web API HTTP PUT方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些资源-UserProfile

I have some resource- UserProfile

public UserProfile
{
   public string Email{get;set;}
   public string Password{get;set;}
}

我想分别更改电子邮件"和密码"(一次只能为一个用户更改).我有一个Web API控制器,例如/api/user/123,它以RESTful风格处理请求.遵循RESTful风格,我应该具有用于​​更新资源的一个方法 PUT ,但是我有两个任务可以更新相同的资源api/user/123.我需要向PUT请求主体添加一些功能,例如{email:'test@domain.com', changeType:'email '}或{password:'12345678', changeType:'password'}可以写一些我的PUT方法?还是有其他方法以RESTful风格更新我的资源?

I want to change Email and Password separatly (only one for user at same time). I have web api controller for example /api/user/123 that handle requests in RESTful style. Follow the RESTful style i should have one method PUT which update the resource, but i have two task that update the same resource api/user/123. I need to add some feature to PUT request body like {email:'test@domain.com', changeType:'email'} or {password:'12345678',changeType:'password' } to write some if in my PUT method ? Or there is some other way to update my resource in RESTful style ?

推荐答案

您有两个选项可以分别更新电子邮件和密码.

You have two options for updating email and password separately.

A)不要使用PUT,请使用POST

A) Don't use PUT, use POST

B)创建子资源以更新各个元素,例如

B) Create child resources for updating the individual elements, e.g.

PUT /api/user/123/email

还有

PUT /api/user/123/password

这篇关于asp.net Web API HTTP PUT方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆