is it possible to create a Grafana variable (used in queries) from a http endpoint. The http endpoint returns a json, like this
{
"var": 1
}
The variable value should be 1 in this case.
Related
according to examples from https://cli.github.com/manual/gh_api:
# print only specific fields from the response
$ gh api repos/{owner}/{repo}/issues --jq '.[].title'
GitHUb CLI (gh) can use the '-q' or '--jq' argument followed by a query string to select values from the response and e.g. display only certain fields.
I'd like to do a similar thing using either CURL, postman or JavaScript fetch().
So my question is: is the --jq query string sent (somehow) by gh CLI as part of an http request and processed on the server (to reduce the amount of data in the response), or is it only applied on the client side as post-processing of the data received ?
And if that query string can be passed to and processed on the server, how should it be specified if I need to make the request not with gh but with curl, postman or javascript fetch() method?
I fear the processing is actually done on the client, meaning the http response will always provide the full data...
Can someone confirm this?
Thanks!
The response is filtered on the client. You can verify yourself by taking a look at the source code:
if opts.FilterOutput != "" && serverError == "" {
// TODO: reuse parsed query across pagination invocations
err = jq.Evaluate(responseBody, bodyWriter, opts.FilterOutput)
if err != nil {
return
}
}
curl, postman, fetch
Your goal is to make an HTTP Request, not use the gh CLI.
GitHub's GraphQL API is what you seek:
To create integrations, retrieve data, and automate your workflows, use the GitHub GraphQL API. The GitHub GraphQL API offers more precise and flexible queries than the GitHub REST API.
GraphQL only returns the data requested. The data is "processed" on the API server and then sent to the client.
so I understand that this is not valid
Contract dsl =
Contract.make {
description "should return correct expected response"
request {
method GET()
url value(consumer(regex('/v2/abc/user/[0-9]{9,18}')),producer(regex("/abc/v2/user/[0-9]{9,18}")))
}
}
response {
body([
id : $(consumer(regex('.*'))),
])
status 200
}
}
The API gateway between the two sides producer and consumer transforms producer url to consumer. Does the spring cloud contract allow for such cases where API gateway changes the URL to look what is expected by the consumer?
When I try to do this the error is pretty clear
You can't have a regular expression for the request on the server side
It makes no sense to have a regex on the producer side. That's because in the tests we need to send a concrete request to a concrete url. We can't find the url unless you tell us how it looks like.
I have seen people use NewRequest() method of the "net/http" package for testing APIs. Why not use the NewRequest() method from "net/http/httptesting"? What's the difference? Documentation advises the following:
// To generate a client HTTP request instead of a server request, see
// the NewRequest function in the net/http package.
What would be the difference in handling cookies, for example? Both seem to be very similar.
TL;DR: they're the same type, used a bit differently for two use cases and initialized differently to serve these use cases
The difference is only in usage - they are the same type http.Request. http.NewRequest is used for the more "production" use case which is client - "create a new request to send to the server". When writing HTTP servers, it's occasionally useful to create requests for testing, which is what httptest.NewRequest does. The doc of http.NewRequest is helpful here:
NewRequest returns a Request suitable for use with Client.Do or
Transport.RoundTrip. To create a request for use with testing a Server
Handler, either use the NewRequest function in the net/http/httptest
package, use ReadRequest, or manually update the Request fields. See
the Request type's documentation for the difference between inbound
and outbound request fields.
If you check the docs of the http.Request type, you'll find things like:
// URL specifies either the URI being requested (for server
// requests) or the URL to access (for client requests).
//
// For server requests, the URL is parsed from the URI
// supplied on the Request-Line as stored in RequestURI. For
// most requests, fields other than Path and RawQuery will be
// empty. (See RFC 7230, Section 5.3)
//
// For client requests, the URL's Host specifies the server to
// connect to, while the Request's Host field optionally
// specifies the Host header value to send in the HTTP
// request.
URL *url.URL
Note the "For client requests" vs. "For server requests".
If you see a place that doesn't use httptest.NewRequest it could be because:
They're not aware of it
Or they need more careful fine-tuning that http.NewRequest doesn't provide
I am using Akka HTTP and having the following HTTP request:
http://www.example.com?p1=1&p2=2&p3=http://www.example.net?a=1&b=2%203
Is there a way in Akka HTTP to get the full raw (not URL decoded) request URL? I would like to get the full raw request URL as it is
http://www.example.com?p1=1&p2=2&p3=http://www.example.net?a=1&b=2%203
parse it and get everything after "p3=".
Turn on the akka.http.server.raw-request-uri-header configuration setting, and the raw request URI will be included as the value for a header named Raw-Request-URI.
In other words, in your application.conf, set the following:
akka.http.server.raw-request-uri-header = on
Then obtain the raw request URI from the Raw-Request-URI header.
From the documentation:
Sometimes it may be needed to obtain the “raw” value of an incoming URI, without applying any escaping or parsing to it. While this use case is rare, it comes up every once in a while. It is possible to obtain the “raw” request URI in Akka HTTP Server side by turning on the akka.http.server.raw-request-uri-header flag. When enabled, a Raw-Request-URI header will be added to each request. This header will hold the original raw request’s URI that was used. For an example check the reference configuration.
Which possibilities are provided by the HTTP protocol to transmit data and parameters from client to server?
Parameters included into the url (PathParams, QueryParams, MatrixParams)
Header parameters like CookieParams, any other custom header param
HTTP body whose content type is defined via the header param Content-Type (FormParams, and any other post data)
Is that correct and complete?