REST parameters: object vs native datatypes
In designing a WCF REST Service utilizing JSON as the messaging format, is it best to pass serialized JSON objects to the WCF service or JSON containing the parameter value pairs?
In other words, what method signature would be best:
public void CreateUser(User user);
or
public void CreateUser(string userName, string firstName, string lastName, string email, string password);
The User object would contain properties for UserName, FirstName, LastName, Email, and Password.
It seems to me that it would be easier for a consumer to use the later开发者_Go百科 signature because it removes the question on what the User object actually needs to contain.
Are my thoughts correct?
Actually - I would expect a REST-ful API to create a user to look like an HTTP POST to e.g.
http://myhostname/users/
where the body of the request contains the fields required to construct a new User object.
The Web service will then create the object, persist it, and return a URI to the object to allow it to be retrieved later. For instance here it might return
http://myhostname/users/DanWaterbly
It's rather easier for the consumer to use this kind of approach as a properly written deserializer will be tolerant of extra or missing elements in the User object.
精彩评论