1 /** 2 Web.d version 2.0 3 4 Goals: 5 1) Keep the api provider stuff but cleaner 6 2) Make RESTful objects easier to use 7 like rails in part: index, show, delete, update, create, new 8 also allowing http verbs like in the first version 9 3) Have sane composition through and through 10 aliasing other objects in should work 11 and form a chain of pre/post processors 12 4) Have less templated stuff and immutable reflection info 13 tied to typeinfo or something 14 5) Cleaner auto-formatting 15 6) Nice customization using UDAs 16 7) More batteries included (templating, css, etc.) 17 also including link helpers with static checks if possible 18 8) Better support for automated composition calls 19 9) Code generation for other languages - JS, PHP, D, and XML 20 10) Plugins from other sources that can be dropped in 21 11) Higher performance on things like embedded_httpd 22 23 Formats: 24 json, xml, html 25 table, csv, raw, string 26 */ 27 module arsd.web2; 28 29 version(none) 30 class TestCase : ApiProvider { 31 struct Bar { 32 int a; 33 string b; 34 } 35 36 // should accept b.a=10&b.b=foo and return {"a":10,"b":"foo"} 37 Bar identity(Bar b) { return b; } 38 } 39 40 /++ 41 GET /user -> redirect /users -> User.index() ... maybe? 42 43 GET /user/10 -> new User("10").show() 44 45 GET /user/10/method -> new User("10").method(); 46 47 /* POST creates a new thing */ 48 POST /user/10 foo=bar -> auto u = new User("10"); u.foo = bar; /* property i hope */ u.update(); 49 50 DELETE /user/10 -> new User("10").destroy(); 51 alternatively 52 POST /user/10/delete 53 54 GET /user/10/edit -> gets an editing form 55 POST /user/10/edit -> saves changes. Alternatively: PUT /user/10 56 PUT /user/10 -> new User("10").save(); /* PUT does create or update */ 57 PATCH doesn't replace it entirely. it is prolyl preferable 58 59 GET /user/new -> gets a new form. hmm. 60 POST /user/new -> creates a new one. 61 or alternatively POST /user 62 63 Note: ONLY get and post work on html forms 64 +/ 65 66 /+ 67 class User : RestResource { 68 this(ApiProvider provider, string identifier) { 69 // if identifier is null, it is asking for an index 70 } 71 72 Document show() {} 73 74 void update(string[] fieldList/*, other args... */) { 75 76 } 77 } 78 79 80 interface RestMeta { 81 Element getHtml(RestResource) {} 82 string getJson(RestResource) {} 83 void deleteItem(RestResource) {} 84 } 85 86 void ourmain(Cgi cgi) { 87 88 } 89 90 import arsd.cgi; 91 mixin GenericMain!ourmain; 92 +/