Re-work URL method and path specification
Closed this issue · 7 comments
Currently in org-mode URL specification looks like:
#+BEGIN_SRC es :method post :url localhost:9200/foo
{
"mappings": {
"doc": {
"properties": {
"body": {"type": "string"}
}
}
}
}
#+END_SRC
However, when this org-mode file is exported, there is no way to tell what the HTTP method and URL are, only the body is actually exported.
We should figure out a way to specify the URL/Method that can also be exported, for example:
#+BEGIN_SRC es :base-url localhost:9200
POST /test-index
{
"mappings": {
"doc": {
"properties": {
"body": {"type": "string"}
}
}
}
}
#+END_SRC
/cc @ljos interested in your thoughts about this; in the current behavior, this is one of the downsides to having the URL specified only as part of the header.
The problem that I have is that I want to, like I said earlier, be able to call the resulting file by curl -XPOST localhost:9200/index --data-binary @mappings.es
. If we have a header I would need to do curl -XPOST localhost:9200/index --data-binary @<(tail -n+2 mappings.es)
instead. (The reason for the <()
is that mappings.es
might be a large file.)
We could support both types of syntax where if you write :base-url
the src-block is tangled with POST url
as a header and if you use url
it does not. I think it should default to the current behaviour though.
Can you post an example of a document you're using this with? That may help clarify our different use cases.
Oh okay, I think I see what you're saying now. I think we can solve this in a way that will work for both of us, I'll work on that :)
@ljos check out the sense-like-parameters
branch (see the test2.es
file for an example), which adds support for what I was talking about, while retaining support for non-parametrized requests.
C-c C-c
now executes either the region, if one is selected, or searches for a header if used without a region. C-c C-a
is now bound to execute either a region if selected, or the whole buffer if not.
Needs more work for fontification and org-mode support, but I think it should solve the issue for both of us, what do you think?
I looked quickly over it. It looks nice. Can you make it a PR and we can start commenting in the source and continue this discussion there?
Good idea, opened an issue.