asp.net web API HTTP PUT method

前端 未结 2 785
不思量自难忘°
不思量自难忘° 2021-01-23 16:59

I have some resource- UserProfile

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

I want to change

相关标签:
2条回答
  • 2021-01-23 17:34
    [HttpPut]
    public HttpResponseMessage PutProduct(Product p)
    {
        Product pro = _products.Find(pr => pr.Id == p.Id);
    
        if (pro == null)
            return new HttpResponseMessage(HttpStatusCode.NotFound);
    
        pro.Id = p.Id;
        pro.Name = p.Name;
        pro.Description = p.Description;
    
        return new HttpResponseMessage(HttpStatusCode.OK);
    }
    
    0 讨论(0)
  • 2021-01-23 17:39

    You have two options for updating email and password separately.

    A) Don't use PUT, use POST

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

    PUT /api/user/123/email
    

    And

    PUT /api/user/123/password
    
    0 讨论(0)
提交回复
热议问题