简体   繁体   中英

GET operation difference in normal web service and REST web service

I have a doubt on GET operation of normal and REST web services. I understand REST services are based on the HTTP VERBS. So, for a entity, if there are couple of GET methods, how would it differentiate.

Below is the example of basic service

public class CustomerService
{
  public List<Customer> GetCustomers()
  {
     //returns all customers
  }

  public List<Customer> GetCustomersWhoHaveOrdersAndOtherFilterCriteria(int orderid,string name)
  {
     //returns filtered customers
  }
} 

If it is normal web service, it can be called via CustomerService/GetCustomers or CustomerService/GetCustomersWhoHaveOrdersAndOtherFilterCriteria/23 but how about REST web service, I assume there should be one GET operation.

1) In "normal" web service - if you mean SOAP you are never using GET - all requests are wrapped in POST

2) REST Url shall contain reference to resource - eg Customer not to operation so the result url could be CustomerService/Customers for http method GET

3) For orderid and name parameters there are more options:

CustomerService/Customers/orderid/123/name/MyName001
CustomerService/Customers?orderid=123&name=MyName001

and more

You are right as you said that Rest services are based on HTTP verbs . But there is one more thing that is Rest services are basically Resource based and Resources are nothing but the Url.
So what you can do is you can create different uri template for accessing different services

CustomerApi/Customer --  HTTP GET -- GET All Customers
CustomerApi/Customer/FilterID -- HTTP GET -- Get filter customer

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM