Fossil JSON API: How to create a wiki page? - json-api

I've been trying to create a wiki page, ufollowing the documentation of the Fossil JSON API. When I put the URL http://myrepo.top/json/wiki/create?name=test I get and answer similar to:
{"fossil":"81d7d3f43ebd4e77095cfbacee7ebc9ae043a014760cde56d437dbd8b6a37c92","timestamp":1496771043,"resultCode":"FOSSIL-3002","resultText":"'name' parameter is missing.","command":"wiki/create","procTimeUs":4000,"procTimeMs":4}
I don't know how the page name is supposed to be given in the URL. I was imagining that was similar to the way you query wiki pages, but seems that the API is expecting something different. Could someone show me the proper way of adding the page name to the Fossil JSON API URL?
Thanks,

In the Fossil mailing list Warren gave me an answer on how to proceed:
curl -H "Content-Type: application/json" \
-d '{"authToken": "nunyabinness", \
"payload": {"name": "foo", "content": "bar"} }' \
http://localhost:8080/json/wiki/create
and that gives me the proper wiki page.

Looking at the source code, it would seem you need to send the new wiki page name in the body of the POST request:
{ name: "test"
, content: "# Test\n\nThis is a test page."
, mimetype: "text/x-markdown"
}
If I read the code correctly, both name and content need to be specified in the JSON body, but the mimetype can be specified either as a GET parameter, or in the JSON body.
Disclaimer: I haven't tested this code, since I have no JSON-enabled instance of Fossil at hand.

Related

How to configure http request with "form" in elm

I just started learning elm this week so excuse me if the question is super basic.
So, I want to send a keyword (which is part of my Model, as shown in the forms example at https://elm-lang.org/examples/forms) as a "form" from my elm frontend to my backend. My cURL HTTP request looks like this:
curl -X 'POST' --form 'keyword=key' 0.0.0.0:5000/search
How would I transform that into an HTTP request written in elm, specifically the --form part? I read the HTTP section in the elm guide, but it doesn't mention anything about this.
--form corresponds to a multipart request, which you can use Http.multipartBody to construct. This is the equivalent of your example curl request.
Http.post
{ url = "http://0.0.0.0:5000/search"
, body =
Http.multipartBody
[ Http.stringPart "keyword" "key"
]
, expect = Http.expectString GotText
}
With a multipartBody you can also post files and blobs with filePart and bytesPart, respectively, in addition to simple key-value pairs as done here using stringPart

Sending POST request with form-data works, but its simple raw equivalent doesn't

I am trying to send a Post request to my server, and here is the thing, when I try doing that with "form-data" everything works absolutely fine.
you can see what I wrote below:
form-data
But when I send it as a raw Json, it doesn't work at all...
below is the body that contains the json code:
{
"cookie": "test1|1521275188|udWlZft3jKw8HYBmni7F2LzctUFBCSDOzahc63Jm6Gk|2a7f91a7d68e2c10399706ba3f9e2833123ddb17e1de2f2d7a669b47ff701ab0",
"nonce": "84d874e5b7",
"title": "post Try" }
as you can see, I wrote a key and a value in both places, but one works and the other doesn't, and because I only sent 3 parameter I don't really see any place for a spelling mistake...
What do you think it might be?
Thank you!
You need to send the object too, the form wraps the form-data inside the object
something like,
"post":{
{
"cookie": "test1|1521275188|udWlZft3jKw8HYBmni7F2LzctUFBCSDOzahc63Jm6Gk|2a7f91a7d68e2c10399706ba3f9e2833123ddb17e1de2f2d7a669b47ff701ab0",
"nonce": "84d874e5b7",
"title": "post Try" }
}

How to execute ElasticSearch agg query from Apache Nifi using InvokeHTTP?

I want to execute the following query from Apache Nifi:
GET /myindex/_search
{
"size": 0,
"aggs": {
"range": {
"date_range": {
"field": "Datetime",
"ranges": [
{
"from": "2017-02-17T16:00:00Z||-1H/H",
"to": "2017-02-17T16:00:00Z||/H"
}
]
}
}
}
}
I want to get the value of doc_count.
I tried to use InvokeHTTP and directly pasted the above-defined query into the field HTTP Method. I also set Remote URL to http://localhost:9200. I connected InvokeHTTP with PutFile in order to save a response on the disk. The relationship is Response.
When I run InvokeHTTP, it does not give me any error. However, it neither outputs any result (FlowFile for Response). I am sure that the result is not an empty set, because I tested this query with curl.
What is wrong with my approach? Should I define HTTP Method in some different way?
For verbs like POST, PUT, and PATCH, you'd normally have the above JSON body as the content of a flow file and pass that to InvokeHttp, setting the correct verb and URL there. However the InvokeHttp documentation states that the message body will not be sent for a GET verb.
The good news is that the Elasticsearch REST API for the search endpoint supports both GET and POST. From their latest doc: "Both HTTP GET and HTTP POST can be used to execute search with body. Since not all clients support GET with body, POST is allowed as well."
I would set the content of a flow file to the above JSON body (perhaps using GenerateFlowFile or ReplaceText), then use POST as the verb.
There is a JsonQueryElasticsearch processor, which supports JSON elasticsearch queries.
Your query goes into the Query field.
The processor has hits and aggregations relations for you to process the result.

How to set the format of a reply to a REST service in BW6

I'm new to BW6 (v.6.3.1) and I'm playing around with it's REST features.
Currently I'm building a very simple echo service to figure out how it processes parameters etc.
One of the things I've noticed is that I can specify multiple Reply Client Formats, namely XML & JSON. But I can't find how I can specify what output to use in the actual reply.
Currently I've setup the following Resource Service Path:
/echo/{param}.{format}
I want to use the format parameter to drive the output I'll be getting. So
/echo/printme.xml
would result in
<messageBody>printme</messageBody> (or something to that extent)
And
/echo/printme.json
would result in
printme
I've tried several approaches, splitting the flow based on the contents of "format" but to no avail. If I have JSON checked as the Reply Client Format it will reply with JSON. Only if XML is the only Reply Client Format checked the reply will output XML. BW handles the rendering of either JSON or XML transparently.
So, how can I tell BW to output in either XML or JSON when both are selected as a Reply Client Format?
Edit:
Using the swagger UI I figured out how I can drive this behavior. By specifying the following header:
curl -X GET --header "Accept: application/xml" "http://localhost:8080/echo"
As per the documentation
Select the Invoke REST API pallette, you can choose the type(either request or response) as shown below:
If you click on it, there are three options JSON, XML and Custom. If you want to choose other than json and xml then choose Custom.
Custom(For RequestType) : Custom: to override the Content-Type value in the Input tab, select CUSTOM and provide the value in the Input tab.
Custom(For ResponseType): to override the Accept header value in the Input tab, select CUSTOM and provide the value in the Input tab.
Below is the Input tab where you can override when type is Custom:

How to send HTTP POST requests using only Rebol3

What is the simplest way of sending HTTP POST requests and getting response (in XML format for example) using only Rebol3?
Is there an equivalent of using read/custom in Rebol2, as it is done in this question?
How to send an HTTP post with a custom header using REBOL
And where should I be donwnloading my Rebol3 binaries from? I've not found a lot of documentation on that...
The documentation at on Ports: Synchronous and Asynchronous Operations shows how to use both GET and POST. To summarize:
The default behavior is to assume the post data should be considered as application/x-www-form-urlencoded. (If you want to encode a block of ordinary Rebol data into that format, see %altwebform.r)
result: write http://www.rebol.com/cgi-bin/updata.r data
If you need a custom header, then instead of passing a string you need to pass a block. Start it with the WORD! post followed by a block of Rebol-formatted key/value pairs, and then your data:
result: write http://www.rebol.com/cgi-bin/updata.r compose [
post [
Content-type: "text/x-rebol"
;-- other fields here
]
(data)
]
The result will be in binary! and can be converted to string! to parse out any XML or whatever.
where should I be downloading my Rebol3 binaries from?
You should download binaries from http://www.rebolsource.net/

Resources