RESTool
RESTool copied to clipboard
Do not send field when in url
I'm trying to use RESTool with an API that, when creating a new user, requires a PUT request with the new user name in the URL.
Now if I define
"post": {
"actualMethod": "put",
"url": "/users/:username",
"fields": [
{
"name": "username",
"type": "text",
"label": "User name"
},
{
"name": "password",
"type": "text",
"label": "Password"
}
]
}
the server returns an error because the field is not expected in the body. However, if I don't define it in "fields", the UI will not generate a corresponding input field.
A possible solution would be exclude the field from the body if it is already part of the url.
Perhaps there is a solution with custom fields, but if so, I don't know how to use them for an "Add Item" functionality.
I also noticed that ":username" won't be replaced at all in my url, so it looks like POST works differently which appears unexpected and unnecessarily inconsistent to me, although I see there was a good reason for this – the REST API I'm trying to work with does not adhere to the standards well.
I checked the customActions functionality, but with that, I seem unable to create something like the Add Item button, because I can only add actions to the items in the item list.
@cubistico you may add the useInUrl
property on this field and set it to true
. I think this will solve it.
@cubistico you may add the
useInUrl
property on this field and set it totrue
. I think this will solve it.
I'm afraid it doesn't. This is the url it generates with useInUrl
:
http://my.test.server/users/:username?username=aaa
Not what I would expect. Plus, it still also includes username
in the body, which is actually what is stated in the docs:
If true, a field can be used as a parameter in a PUT url. Otherwise only fields retrieved in the original GET can be used as parameters. Its data will still be added to the PUT request body.
I wonder if that makes sense in any scenario? I would think that the data would be expected in either the url or the body?
Hmmm I guess it makes sense, but currently not supported. You're more than welcome to add it :)