how m.quest pass array parameter when using POST method - mithril.js

something like this:
m.request({method: 'POST', url: '/load/users', data: {'q[]': array}})
but the result is
"invalid param 'q[]': empty"

Related

Karate - how to use param from response to test child endpoints

I have a parent URL that returns an array of objects with id and slug, this is dynamically generated because it depends of the user (test env). After getting this data, how can I dynamically call each element object from an array and make another request ?
Example :
Scenario: parent
Given url 'posts'
Then Status 200
* assert response.status == true
Example url/posts returns a data of array of objects :
[
{id: 6, slug: 'my-post-6'},
{id: 23, slug: 'example-test-23'},
{id: 133, slug: 'another-test-133'},
]
Then I want to make a get request to every object like so : url 'posts/' data.slug
How can I do this ?
GET url 'posts/my-post-6'
// Validate schema
GET url 'posts/example-test-23'
// Validate schema
GET url 'posts/another-test-133'
// Validate schema
Karate's call keyword auto-loops over a JSON array of objects. Refer the docs: https://github.com/karatelabs/karate#data-driven-features
You can try this simple example:
Feature:
Scenario:
* def data = [{ slug: 'one'}, { slug: 'two'}]
* call read('#called') data
#called #ignore
Scenario:
* url 'https://httpbin.org/anything'
* path slug
* method get
This is getting improved in future versions, refer: https://github.com/karatelabs/karate/issues/1905 (available now in 1.3.0.RC2)

JWS Error during API testing python flask

I am trying to test a function, which basically calls the API by passing a some values, which is then loaded to the schema to be validated and then accepted or rejected based on validation.
The below is my test function.
params = {
'first': [10,20],
'second': 400,
'third ': 'Testing'
}
headers = {
'Authorization': 'Bearer{}'.format(token),
'Data-type' : "json"
}
response = self.client.post(url_for('MyView:post', id=current_id.id),
json=params,
headers=headers)
This renders me the error below:
{
"msg": "Invalid header string: must be a json object"
}
I was able to check the issue and found out its due to the mapping of invalid types. But as headers is still a dictionary, I am not able to comprehend why this error is being rendered.
I have also added the structure of my schema and API below:
class MySchema(marshmallow.Schema):
id = fields.Integer(required=True)
second = fields.Integer(fields.Integer(), required=True)
first = fields.List(fields.String(), required=False)
third = fields.Str(validate=validate.Length(min=0, max=255), required=False)
class Meta:
fields = ('id',
'second',
'first',
'third')
#validates_schema(pass_original=True)
def validate_numbers(self, _, data):
//function code
The below is the structure of my API
class MyView(V1FlaskView):
#jwt_requried
def post(id):
//code
Maybe a space character is missing after Bearer:
'Authorization': 'Bearer {}'.format(token),

Alamofire.upload with query parameters

I'm using Alamofire.upload to upload an image as a .POST multipart to my server. But my server always gets parameters only as a query string, and use multipart only for a file data. So in my request I also need to put some parameters to URL, but it seems Alamofire.upload have't a variant with parameters argument.
Alamofire.upload(
.POST,
"https://httpbin.org/post?user=\(userId)&photo=\(photoTitle)",
multipartFormData: { multipartFormData in
multipartFormData.appendBodyPart(fileURL: unicornImageURL, name: "unicorn")
},
encodingCompletion: nil
)
For now I just put all parameters by myself directly forming request-string: "https://httpbin.org/post?user=\(userId)&photo=\(photoTitle)".
Is there a better way to pass query parameters to Alamofire.upload?
What can do things better is Alamofire.ParameterEncoding, but it will need some workaround with requests.
var req: NSMutableURLRequest?
(req!, _) = Alamofire.ParameterEncoding.URL.encode(
NSURLRequest(URL: NSURL(string: "https://httpbin.org")!),
parameters: ["user": userId, "photo": photoTitle]
)
Alamofire.upload(
.POST,
req!.URLString,
multipartFormData: { multipartFormData in
multipartFormData.appendBodyPart(fileURL: unicornImageURL, name: "unicorn")
},
encodingCompletion: nil
)

Chinese Characters not being updated in SQL field

I have an update statement with Chinese characters in the data like so...
UPDATE table SET col1 = N'点心' WHERE id = 123
I am declaring the content type as UTF-8. For some reason, the field get updated with this:
自然地解é
The field is a nvarchar in MSSQL. Any ideas?
**EDIT
I am using a jQuery ajax call to write the data:
jQuery.ajax({
type: "POST",
url: "ajax/call.asp",
data: { value: value },
contentType:"application/x-www-form-urlencoded;charset=UTF-8",
dataType: "json",
success: function(msg){}
});
** EDIT
Page 1 is:
<script>
var value = "<%=value%>";
jQuery.ajax({
type: "POST",
url: "ajax/call.asp",
data: { value: value },
contentType:"application/x-www-form-urlencoded;charset=UTF-8",
dataType: "json",
success : function(responseData) {}
});
</script>
Page 2 is:
value = Request("value")
IF value <> "" THEN
SQL = "UPDATE table SET col1 = N'"& value &"' WHERE ID = '123'"
objconn.execute(SQL)
END IF
Figured it out. My text editor wasn't saving the ajax file as UTF-8 UOM. Once it saved this way, it worked.

MALFORMED QUERY: Encountered " "delete" "DELETE

While trying to delete triplets I get following error:
MALFORMED QUERY: Encountered " "delete" "DELETE
Was expecting one of:
"base" ...
"prefix" ...
"select" ...
"construct" ...
"describe" ...
"ask" ...
My query was:
DELETE {
?s example:id 'Id' .
};
Sesame with Jetty is what I am using. I sent an HTTP request. I have another question opened around this
delete rest api to remove statements from global context
I might be sending to wrong endpoint. My endpoint looks like:
http://example.com/openrdf-sesame/repositories/$repo/
Please help.
EDIT:
self.baseURLRepositories = storeUrl + "/openrdf-sesame/repositories/"
endpoint = self.getBaseURLForSesameRepositories() + "%s" % (self.getRepository())
params = { 'query': query }
headers = {
'content-type': 'application/x-www-form-urlencoded',
'accept': 'application/sparql-results+json'
}
(response, content) = httplib2.Http().request(endpoint, 'POST', urllib.urlencode(params), headers=headers)
results = json.loads(content)
where query = DELETE ...
You are using an incorrect endpoint location. SPARQL update requests should be sent to openrdf-sesame/repository/<repid>/statements.