I have two development paths regarding what a return value should be from a RESTful architecture standpoint. What are the pros and cons of each method below?
First method.
The Client will submit a post of item Hologram. Here is the model in method one.
public class Hologram
{
public double HoloWidth { get; set; }
public double HoloHeight { get; set; }
public double HoloDepth { get; set; }
public string HoloGuid { get; private set; }
public Hologram()
{
this.HoloGuid = new Guid().ToString();
}
}
The idea is, that this method will be able to provide a faster response to the client, because I will return a guid immediately associated to this Hologram.
Here is the repository for method one, I don't have the database connection set up yet but _holos will be the database.
public string Add(Hologram hg)
{
Hologram hig = new Hologram();
hig = hg;
AsyncCode(_holos.Values.Add(hig)); /// this adds to the database via injection, running asynchronously.
return hig.HoloGuid;
}
Second method.
The client will submit a post of item Hologram as well, but the model is a bit different.
public class Hologram
{
public double HoloWidth { get; set; }
public double HoloHeight { get; set; }
public double HoloDepth { get; set; }
public string HoloId { get; set; }
public Hologram()
{
}
}
The idea for this method is somehow the Stored Procedure or EntityFramework that inserts a new record into the database will return the id ( I haven't figured out how to get the id yet). Once this happens, the ID of the Hologram can go back to the App server, and then provide the return id. Here is the Repository for the second method.
public int Add(Hologram hg)
{
_holos.Values.Add(hg); ///adds to database via injection
///hg will have the ID from the database at this point... somehow.
return hg.ID;
}