Wiki source code of ERRest In Depth

Version 42.1 by Pascal Robert on 2012/06/10 15:08

Show last authors
1 General architecture
2 Same Origin policy
3 Transactions
4 HTML vs other formats
5 Response representation
6 Missing route
7 Missing object
8 POJO objects
9 Headers
10 Caching
11 Adding new format
12 Security
13 strictMode
14 Workflow
15 Query arguments and RXRestFetchSpecification
16 ERXRestNameRegistry
17 MapClassDescription / NSDictionaryClassDescription
18
19 Calling an action goes like this:
20
21 {{code}}
22
23 Application.dispatchRequest ->
24 ERXRouteRequestHandler.handleRequest ->
25 ERXRouteRequestHandler._handleRequest ->
26 RestEntitiesController(ERXRouteController).performActionNamed ->
27 RestEntitiesController(ERXRouteController).performRouteActionNamed -> RestEntitiesController(ERXRouteController).performActionWithArguments(Method, Object...) ->
28 Method.invoke -> ...
29 RestEntitiesController.indexAction()
30
31 {{/code}}
32
33 ERXRestUtils
34
35 request > route
36
37 {{code}}
38
39 /**
40 * A NameFormat that behaves like Rails -- plural entities, plural routes, lowercase underscore names
41 * (names_like_this).
42 */
43 public static NameFormat RAILS = new NameFormat(true, true, NameFormat.Case.LowercaseUnderscore);
44
45 /**
46 * A NameFormat that behaves like WO -- singular entities, singular routes, camel names (NamesLikeThis).
47 */
48 public static NameFormat WO = new NameFormat(false, false, NameFormat.Case.CamelCase);
49
50 /**
51 * A NameFormat that behaves like WO -- singular entities, singular routes, lowercase camel names (namesLikeThis).
52 */
53 public static NameFormat WO_LOWER = new NameFormat(false, false, NameFormat.Case.LowerCamelCase);
54
55 {{/code}}
56
57 * ERXRestContext
58 ** contains the editing context and an userInfo dictionnary
59 ** will be populated with er.rest.dateFormat, er.rest.timestampFormatter and er.rest.timestampFormat (read only for non-HTML responses)
60 *** want to change the time format for a specific controller?
61
62 {{code}}
63
64 protected ERXRestContext createRestContext() {
65 ERXRestContext restContext = new ERXRestContext(editingContext());
66 restContext.setUserInfoForKey("yyyy-MM-dd", "er.rest.dateFormat");
67 restContext.setUserInfoForKey("yyyy-MM-dd", "er.rest.timestampFormat");
68 return restContext;
69 }
70
71 {{/code}}
72
73 *
74 ** you just need to override createRestContext() in your controller if you want to add other stuff to the context (a user, etc.)
75 * Properties
76 ** ERXRest.idKey (ERXRestFormatDelegate)
77 *** (default "id") Override this property if you want to use a different key for the 'id' attribute** ERXRest.typeKey**
78 ** ERXRest.nilKey (ERXRestFormatDelegate)
79 ** ERXRest.writeNilKey (ERXRestFormatDelegate)
80 ** ERXRest.pluralEntityNames (ERXRestFormatDelegate)
81 ** ERXRest.writeTypeKey (ERXRestFormatDelegate)
82 ** ERXRest.suppressTypeAttributesForSimpleTypes (ERXXmlRestWriter)
83 *** (default "false") If set to true, primitive types, like type = "datetime", won't be added to the output
84 ** ERXRest.strictMode
85 *** In ERXMissingRouteController: (default "true") If set to true, status code in the response will be 405 Not Allowed, if set to false, status code will be 404 Not Found
86 *** In ERXRouteController: (default "true") If set to true, status code in the response will be 405 Not Allowed, if set to false, status code will be 404 Not Found
87 *** ERXRouteResults: (default "true") If set to true, creating a ressource will return status code 201 Created, if set to false, will return 200 OK
88 ** ERXRest.pluralEntityNames (ERXRouteRequestHandler)
89 ** ERXRest.routeCase (ERXRouteRequestHandler)
90 ** ERXRest.lowercaseEntityNames (ERXRouteRequestHandler)
91 ** ERXRest.parseUnknownExtensions (ERXRouteRequestHandler)
92 *** (default "true") If set to "false", will return a 404 status code if the format doesn't exist
93 ** ERXRest.missingControllerName (ERXRouteRequestHandler)
94 *** (default "ERXMissingRouteController") Allow you to specify which controller to use when a route doesn't exist
95 ** er.rest.rfcDateFormat
96 ** er.rest.dateFormat
97 ** er.rest.dateFormat.primary
98 ** er.rest.dateFormat.secondary
99 ** er.rest.dateFormatter
100 ** er.rest.timestampFormat
101 ** er.rest.timestampFormat.primary
102 ** er.rest.timestampFormat.secondary
103 ** er.rest.timestampFormatter
104 ** er.rest.rfcDateFormat
105 ** er.rest.jodaTime
106 ** ERXRest.transactionsEnabled (default 'false') ERXRestTransactionRequestAdaptor
107 ** ERXRest.maxEventsPerTransaction (default '50') ERXRestTransactionRequestAdaptor
108 ** ERXRest.accessControlAllowRequestHeaders (ERXRouteController)
109 ** ERXRest.accessControlAllowRequestMethods (ERXRouteController)
110 ** ERXRest.defaultFormat (ERXRouteController)
111 *** (default "xml") Allow you to set the default format for all of your REST controllers
112 ** ERXRest.allowWindowNameCrossDomainTransport (ERXRouteController)
113 ** ERXRest.accessControlMaxAge (ERXRouteController)
114 *** (default 1728000) This header indicates how long the results of a preflight request can be cached. For an example of a preflight request, see the above examples.
115 ** ERXRest.accessControlAllowOrigin (ERXRouteController)
116 *** Set the value to '**' to enable all origins. See [[https://developer.mozilla.org/En/HTTP_access_control#Access-Control-Allow-Origin]]**
117 * JSON Schema
118 ** {{code}}
119 /something?schema=true
120
121 public WOActionResults indexAction() {
122 if (isSchemaRequest()) {
123 return schemaResponse(showFilter());
124 }
125 protected boolean isSchemaRequest() {
126 return request().stringFormValueForKey("schema") != null;
127 }
128 {{/code}}
129
130 Application(ERXApplication).dispatchRequest(WORequest) line: 2051
131 ERXRouteRequestHandler(WOActionRequestHandler).//handleRequest(WORequest) line: 221
132 ERXRouteRequestHandler.getRequestHandlerPathForRequest(WORequest) line: 782//
133
134 ERXRouteRequestHandler(WOActionRequestHandler).//handleRequest(WORequest) line: 259
135 PagesController(ERXRouteController).performActionNamed(String) line: 1328
136 PagesController(ERXRouteController).performActionNamed(String, boolean) line: 1385
137 PagesController(ERXRouteController).performRouteActionNamed(String) line: 1510
138 PagesController(ERXRouteController).performActionWithArguments(Method, Object...) line: 1559
139 ...
140 PagesController.mainPageAction() line: 20//
141
142 == ERXRouteRequestHandler ==
143
144 | **Properties**
145 | ERXRest.missingControllerName | (default "ERXMissingRouteController")
146 \\          
147 | ERXRest.parseUnknownExtensions | ERXRest.parseUnknownExtensions
148 \\          
149 | ERXRest.pluralEntityNames | ERXRest.pluralEntityNames
150 \\          
151 | ERXRest.routeCase | ERXRest.routeCase
152 \\          
153 | ERXRest.lowercaseEntityNames | ERXRest.lowercaseEntityNames
154
155 ERXMissingRouteController is the controller that is used when no route can be found. It's "missing" action is loaded.
156
157 | **Properties**
158 | ERXRest.strictMode | ERXRest.strictMode
159 \\          |
160 ERXRouteController