You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: show a working save_record override for HTTP resources (#659)
* fix: show a working save_record override for HTTP resources
The example built its request from a fictional client and a relative path.
Copied as written that request has no host — HTTParty hands it to Net::HTTP,
which fails on a nil address (AVO-1745, seen in production on avodemo). It now
builds from the resource's own endpoint and evaluates its headers, and both
pages state that the endpoint must be absolute.
Also documents that headers reach create/update/destroy, which they now do.
* Bound the example's hand-rolled request with a timeout
* Encode the example's id like the client does
Copy file name to clipboardExpand all lines: docs/4.0/http-resource-api.md
+4Lines changed: 4 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -51,6 +51,10 @@ self.http_adapter = {
51
51
Unlike the other adapter options, `endpoint` is used verbatim — it does not accept a proc and is not evaluated through `Avo::ExecutionContext`.
52
52
:::
53
53
54
+
:::warning Must be absolute
55
+
The endpoint needs a host. A missing, blank, or relative value (`nil`, `""`, `"/users"`) raises [`Avo::HttpError`](./http-resource.html#handle-api-errors) before any request is sent, so the controller shows a flash message instead of failing inside `Net::HTTP` on a nil address.
56
+
:::
57
+
54
58
:::info Request behavior
55
59
Index requests always carry `page` and `per_page` query parameters — the names are not configurable. Use [`query_params`](#query_params) to send additional parameters. Requests time out after 10 seconds and raise an error.
Copy file name to clipboardExpand all lines: docs/4.0/http-resource.md
+20-7Lines changed: 20 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -87,6 +87,8 @@ self.http_adapter = {
87
87
88
88
If the headers must be computed at request time — rotating tokens, per-user credentials — pass a proc returning the hash instead.
89
89
90
+
Every request carries them: index, show, and count, as well as the create, update, and destroy requests the controller makes.
91
+
90
92
## Map sorting and filtering to query params
91
93
92
94
If you want Avo's sorting UI (or any UI state) forwarded to the API, build the query string with [`query_params`](./http-resource-api.html#query_params). The proc has access to controller `params`, and its result is merged into the request's query string:
@@ -136,7 +138,7 @@ The controller rescues the exception and displays the message as a flash error i
136
138
137
139
## Customize create, update, and destroy
138
140
139
-
Out of the box, the HTTP controller persists changes through the resource's client — `POST` to the endpoint on create, `PATCH` to `endpoint/:id` on update, and `DELETE` to `endpoint/:id` on destroy. The default implementation looks like this:
141
+
Out of the box, the HTTP controller persists changes through the resource's client — `POST` to the endpoint on create, `PATCH` to `endpoint/:id` on update, and `DELETE` to `endpoint/:id` on destroy, each carrying the resource's [`headers`](#send-authentication-headers). The default implementation looks like this:
140
142
141
143
```ruby
142
144
defsave_record
@@ -162,21 +164,32 @@ If your API needs different paths, extra parameters, or conditional logic, overr
Avo configures no `base_uri`, so a relative path — `HTTParty.post("/authors", ...)` — has no host to connect to and fails inside `Net::HTTP` on a nil address, long after the form was submitted. Always request the resource's full `endpoint`.
191
+
:::
192
+
180
193
## Debug console
181
194
182
195
HTTP Resources ship with an interactive debug console for inspecting exactly what your resource sends and receives. Visit `<avo_root>/http-resource/debug` (e.g. `/avo/http-resource/debug`), pick a resource and an action (`index`, `show`, `count`, `create`, `update`, or `delete`), and fire the request.
0 commit comments