c# - Web Api Response Standards -


i have 2 development paths regarding return value should restful architecture standpoint. pros , cons of each method below?

first method.

the client submit post of item hologram. here 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, method able provide faster response client, because return guid associated hologram. here repository method one, don't have database connection set yet _holos database.

        public string add(hologram hg)         {             hologram hig = new hologram();             hig = hg;             asynccode(_holos.values.add(hig)); /// adds database via injection, running asynchronously.              return hig.hologuid;         } 

second method.

the client submit post of item hologram well, model 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 method somehow stored procedure or entityframework inserts new record database return id ( haven't figured out how id yet). once happens, id of hologram can go app server, , provide return id. here repository second method.

public int add(hologram hg)         {             _holos.values.add(hg); ///adds database via injection            ///hg have id database @ point... somehow.             return hg.id;         } 

pros , cons of first method

pros

  • client can receive id faster, without waiting database operation complete.

cons:

  • he received faster, it? if wants immediatly query hologram id, if not inserted yet? if insert failed, how client know that?
  • when generate guids on server, not in database, not sequential. in database can configure generated guids sequential insert performance if have index on guid column (and have such index, because want query guid).

pros , cons of second method

pros , cons of second method reverse of above :) in conclusion, given info provided i'd better use second method, because it's more reliable , more easy implement correctly.


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -