c# - Exposing domain logic in webapi -


so in rest have product resource...

http://api/product 

question if i've got domain logic? in object oriented world, might have

public class product {     int id;      public product(){}      public int calc(int first, int second)     {         return first + second;     } } 

how represent business logic? assume can do...

    public int getcalc(int id, int first, int second)     {         localproduct = products[id];         return localproduct(first + second);     } 

hence url of service become

http://api/product/calc?id=1&first=1&second=2 

or (alternatively)

http://api/product/1/calc?first=1&second=2 

this returns correct result.... i'm wondering if how should represent business business logic? or should doing different way or trying avoid altogether? i'd welcome ideas on how improve this...

this depends on system build. take time think how evolve on time, quite hard refactor. general direction heading looks good.

this api call

http://api/product/calc?id=1&first=1&second=2 

looks right me. have product controller has method calc , takes in parameters id, first , second.

i not sure how deal api

http://api/product/1/calc?first=1&second=2 

to me reads product has many ids, each of id can call method calc parameters first , second. maybe in business domain make sense, fail see it.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -