Wiki source code of ERRest In Depth
Version 32.1 by Pascal Robert on 2012/06/10 12:21
Hide last authors
| author | version | line-number | content |
|---|---|---|---|
| |
31.1 | 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 | ERXRestUtils | ||
| 20 | |||
| 21 | request > route | ||
| 22 | |||
| 23 | {{code}} | ||
| 24 | |||
| 25 | /** | ||
| 26 | * A NameFormat that behaves like Rails -- plural entities, plural routes, lowercase underscore names | ||
| 27 | * (names_like_this). | ||
| 28 | */ | ||
| 29 | public static NameFormat RAILS = new NameFormat(true, true, NameFormat.Case.LowercaseUnderscore); | ||
| 30 | |||
| 31 | /** | ||
| 32 | * A NameFormat that behaves like WO -- singular entities, singular routes, camel names (NamesLikeThis). | ||
| 33 | */ | ||
| 34 | public static NameFormat WO = new NameFormat(false, false, NameFormat.Case.CamelCase); | ||
| 35 | |||
| 36 | /** | ||
| 37 | * A NameFormat that behaves like WO -- singular entities, singular routes, lowercase camel names (namesLikeThis). | ||
| 38 | */ | ||
| 39 | public static NameFormat WO_LOWER = new NameFormat(false, false, NameFormat.Case.LowerCamelCase); | ||
| 40 | |||
| 41 | {{/code}} | ||
| 42 | |||
| |
29.1 | 43 | * ERXRestContext |
| 44 | ** contains the editing context and an userInfo dictionnary | ||
| 45 | ** will be populated with er.rest.dateFormat, er.rest.timestampFormatter and er.rest.timestampFormat (read only for non-HTML responses) | ||
| 46 | *** want to change the time format for a specific controller? | ||
| 47 | |||
| 48 | {{code}} | ||
| 49 | |||
| 50 | protected ERXRestContext createRestContext() { | ||
| 51 | ERXRestContext restContext = new ERXRestContext(editingContext()); | ||
| 52 | restContext.setUserInfoForKey("yyyy-MM-dd", "er.rest.dateFormat"); | ||
| 53 | restContext.setUserInfoForKey("yyyy-MM-dd", "er.rest.timestampFormat"); | ||
| 54 | return restContext; | ||
| 55 | } | ||
| 56 | |||
| 57 | {{/code}} | ||
| 58 | |||
| 59 | * | ||
| 60 | ** you just need to override createRestContext() in your controller if you want to add other stuff to the context (a user, etc.) | ||
| 61 | * Properties | ||
| 62 | ** ERXRest.idKey (ERXRestFormatDelegate) | ||
| 63 | *** (default "id") Override this property if you want to use a different key for the 'id' attribute** ERXRest.typeKey** | ||
| 64 | ** ERXRest.nilKey (ERXRestFormatDelegate) | ||
| 65 | ** ERXRest.writeNilKey (ERXRestFormatDelegate) | ||
| 66 | ** ERXRest.pluralEntityNames (ERXRestFormatDelegate) | ||
| 67 | ** ERXRest.writeTypeKey (ERXRestFormatDelegate) | ||
| 68 | ** ERXRest.suppressTypeAttributesForSimpleTypes (ERXXmlRestWriter) | ||
| 69 | *** (default "false") If set to true, primitive types, like type = "datetime", won't be added to the output | ||
| 70 | ** ERXRest.strictMode | ||
| 71 | *** 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 | ||
| 72 | *** 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 | ||
| 73 | *** ERXRouteResults: (default "true") If set to true, creating a ressource will return status code 201 Created, if set to false, will return 200 OK | ||
| 74 | ** ERXRest.pluralEntityNames (ERXRouteRequestHandler) | ||
| 75 | ** ERXRest.routeCase (ERXRouteRequestHandler) | ||
| 76 | ** ERXRest.lowercaseEntityNames (ERXRouteRequestHandler) | ||
| 77 | ** ERXRest.parseUnknownExtensions (ERXRouteRequestHandler) | ||
| 78 | *** (default "true") If set to "false", will return a 404 status code if the format doesn't exist | ||
| 79 | ** ERXRest.missingControllerName (ERXRouteRequestHandler) | ||
| 80 | *** (default "ERXMissingRouteController") Allow you to specify which controller to use when a route doesn't exist | ||
| 81 | ** er.rest.rfcDateFormat | ||
| 82 | ** er.rest.dateFormat | ||
| 83 | ** er.rest.dateFormat.primary | ||
| 84 | ** er.rest.dateFormat.secondary | ||
| 85 | ** er.rest.dateFormatter | ||
| 86 | ** er.rest.timestampFormat | ||
| 87 | ** er.rest.timestampFormat.primary | ||
| 88 | ** er.rest.timestampFormat.secondary | ||
| 89 | ** er.rest.timestampFormatter | ||
| 90 | ** er.rest.rfcDateFormat | ||
| 91 | ** er.rest.jodaTime | ||
| 92 | ** ERXRest.transactionsEnabled (default 'false') ERXRestTransactionRequestAdaptor | ||
| 93 | ** ERXRest.maxEventsPerTransaction (default '50') ERXRestTransactionRequestAdaptor | ||
| 94 | ** ERXRest.accessControlAllowRequestHeaders (ERXRouteController) | ||
| 95 | ** ERXRest.accessControlAllowRequestMethods (ERXRouteController) | ||
| 96 | ** ERXRest.defaultFormat (ERXRouteController) | ||
| 97 | *** (default "xml") Allow you to set the default format for all of your REST controllers | ||
| 98 | ** ERXRest.allowWindowNameCrossDomainTransport (ERXRouteController) | ||
| 99 | ** ERXRest.accessControlMaxAge (ERXRouteController) | ||
| 100 | *** (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. | ||
| 101 | ** ERXRest.accessControlAllowOrigin (ERXRouteController) | ||
| 102 | *** Set the value to '**' to enable all origins. See [[https://developer.mozilla.org/En/HTTP_access_control#Access-Control-Allow-Origin]]** | ||
| 103 | * JSON Schema | ||
| 104 | ** {{code}} | ||
| 105 | /something?schema=true | ||
| 106 | |||
| 107 | public WOActionResults indexAction() { | ||
| 108 | if (isSchemaRequest()) { | ||
| 109 | return schemaResponse(showFilter()); | ||
| 110 | } | ||
| 111 | protected boolean isSchemaRequest() { | ||
| 112 | return request().stringFormValueForKey("schema") != null; | ||
| 113 | } | ||
| 114 | {{/code}} | ||
| 115 | |||
| |
4.1 | 116 | Application(ERXApplication).dispatchRequest(WORequest) line: 2051 |
| 117 | ERXRouteRequestHandler(WOActionRequestHandler).//handleRequest(WORequest) line: 221 | ||
| |
27.1 | 118 | ERXRouteRequestHandler.getRequestHandlerPathForRequest(WORequest) line: 782// |
| |
4.1 | 119 | |
| |
27.1 | 120 | ERXRouteRequestHandler(WOActionRequestHandler).//handleRequest(WORequest) line: 259 |
| 121 | PagesController(ERXRouteController).performActionNamed(String) line: 1328 | ||
| 122 | PagesController(ERXRouteController).performActionNamed(String, boolean) line: 1385 | ||
| 123 | PagesController(ERXRouteController).performRouteActionNamed(String) line: 1510 | ||
| 124 | PagesController(ERXRouteController).performActionWithArguments(Method, Object...) line: 1559 | ||
| |
4.1 | 125 | ... |
| |
27.1 | 126 | PagesController.mainPageAction() line: 20// |
| 127 | |||
| 128 | == ERXRouteRequestHandler == | ||
| 129 | |||
| 130 | | **Properties** | ||
| 131 | | ERXRest.missingControllerName | (default "ERXMissingRouteController") | ||
| 132 | \\ | ||
| 133 | | ERXRest.parseUnknownExtensions | ERXRest.parseUnknownExtensions | ||
| 134 | \\ | ||
| 135 | | ERXRest.pluralEntityNames | ERXRest.pluralEntityNames | ||
| 136 | \\ | ||
| 137 | | ERXRest.routeCase | ERXRest.routeCase | ||
| 138 | \\ | ||
| 139 | | ERXRest.lowercaseEntityNames | ERXRest.lowercaseEntityNames | ||
| 140 | |||
| 141 | ERXMissingRouteController is the controller that is used when no route can be found. It's "missing" action is loaded. | ||
| 142 | |||
| 143 | | **Properties** | ||
| |
29.1 | 144 | | ERXRest.strictMode | ERXRest.strictMode |
| 145 | \\ | | ||
| |
27.1 | 146 | ERXRouteController |