How do I consume a sparql endpoint - such as DBPedia in an iphone app - iphone

I am looking for tutorials on how to consume and parse data from a sparql endpoint such as DBPedia. I am new to semantic web and rdf and sparql. Would I just treat the response as XML and use one of the many third party xml parsers to read rdf input?
A link to a good tutorial for consuming sparql endpoints on the iphone would be great

You send the query as a HTTP GET request, and parse the result (usually XML or JSON, you can request either) using an XML or JSON parser.
For example the query:
http://dbpedia.org/sparql?query=SELECT+DISTINCT+?concept+WHERE+{+?s+a+?concept+}+LIMIT+50
Will run the SPARQL query:
SELECT DISTINCT ?concept
WHERE {
?s a ?concept .
} LIMIT 50
And return the results in XML.
You can test this in curl with:
$ curl -g 'http://dbpedia.org/sparql?query=SELECT+DISTINCT+?concept+WHERE+{+?s+a+?concept+}+LIMIT+50'
If you set the Accept: header you can control the return type, e.g. in curl:
$ curl -g -H 'Accept: application/json' 'http://dbpedia.org/sparql?query=SELECT+DISTINCT+?concept+WHERE+{+?s+a+?concept+}+LIMIT+50'

Related

VMWare REST Api - access VM host details via REST API

I'm using the VMWare REST API (/api/vcenter/host) to query information about the VM Hosts registered on a vCenter. At the moment I can only seem to get basic info like this :
{
"host": "host-10",
"name": "192.168.18.89",
"connection_state": "CONNECTED",
"power_state": "POWERED_ON"
}
but the Powershell "Get-VMHost | Format-List" has much more useful information such as ESXi version, hardware specs etc.
Can I get this kind of information via the REST API as well?
Thanks!
Yes you can get that kind of information, depending on exactly what info you are wanting. The REST API references are here that you can use to look up what you need. https://developer.vmware.com/apis/vsphere-automation/latest/
For example if you want to know what software is installed you can do something like this.
export basepw=$(echo -n 'administrator#vsphere.local:{password}' | base64)
export token3=$(curl -k -X POST -H "Authorization: Basic ${basepw}" https://{vCenterIP}/api/session/ | tr -d '"')
curl -k -X GET -H "vmware-api-session-id: ${token}" "https://{vCenterIP}/api/esx/software" -H "Content-Type: application/json" -d '{ "auth_type": "EXISTING", "host": "{host-##}"}' | jq .
It looks like vSphere 8 has more options that might fit what you want, like extracting the config https://developer.vmware.com/apis/vsphere-automation/latest/esx/settings/hosts.configuration/
From the looks, some other SDKs would be more developed that the REST API current state. Personally I like govmomi and pyvmomi and both have a CLI tool that can get you started pretty fast. The cli tool for govmomi, govc, doesn't require anything extra to run, so it is fairly portable and might help you with what you are doing.
https://github.com/vmware/govmomi
https://github.com/vmware/pyvmomi

How to pass a parameter to a Spring Cloud Function?

I'm following the Spring Cloud Function tutorial.
In the example, they are calling the revert bean with this command:
curl localhost:8080/reverseString -H "Content-Type: text/plain" -d "abc"
I like to call the endpoint from a browser/postman as a GET request.
So I was looking to orchestrate a URL with a query parameter, that may look like localhost:8080/reverseString?input=abc
But:
It is not clear to me what should be the name of the parameter?
Seems like no matter what method name we put, they all get HTTP 200 response, with no response body. reverseStringggg, reve ...
You can pass it as localhost:8080/reverseString/abc
That said, I've raise the issue to explicitly support http parameters - https://github.com/spring-cloud/spring-cloud-function/issues/864

How to use mitmdump to translate http2 to local http?

I want to use curl http://127.0.0.1:8033/api/v1 to access https://http2.pro/api/v1 with HTTP/2
This API url will return whether the client using http2.
I have tried: (I'm using latest version 5.0.1)
./mitmdump -p 8033 --http2 --set http2_priority=true --mode reverse:https://http2.pro:443
However curl 127.0.0.1:8033/api/v1 still gives:
{"http2":0,"protocol":"HTTP\/1.1","push":0,"user_agent":"curl\/7.69.1-DEV"}
In contrast, curl https://http2.pro/api/v1 --http2 gives: (this is what I expected)
{"http2":1,"protocol":"HTTP\/2.0","push":0,"user_agent":"curl\/7.69.1-DEV"}
mitmproxy currently does not support converting between HTTP/1 and HTTP/2. For HTTP/2 to happen, both endpoints need to speak it. It is on our todo list and will hopefully be possible soon (https://github.com/mitmproxy/mitmproxy/issues/1775).

Rest API to get list of artifacts from Nexus OSS 3.x Repository

I have created a raw repository in Nexus 3.x and I'm able to upload artifacts to the same. Now I want get the list of all artifacts residing inside that repo using Rest API.
Any help is appreciated.
in the current Nexus3.14.0-04 the REST API has become final (no longer "beta") and the curl you need is:
curl -X GET "http://localhost:8081/service/rest/v1/components?repository=central" -H "accept: application/json"
this will return each "component" (group, name, version) with all its assets = each individual file (pom, sha1, md5, jar) who constitue the component
The result is a JSON string.
If instead you want to perform a COMPONENTS search - based on a groupId, artifactId - you can use this curl:
curl -X GET "http://localhost:8081/service/rest/v1/search?repository=central&format=maven2&maven.groupId=com.fasterxml.jackson.core&maven.artifactId=jackson-core&maven.extension=jar" -H "accept: application/json"
this returns COMPONENTS with child ASSETS.
The variant to retrieve only the ASSETS, without grouping them by COMPONENT, is GET /service/rest/v1/search/assets?repository=central&format=maven2&maven.groupId=com.fasterxml.jackson.core&maven.artifactId=jackson-core&maven.extension=jar
You can use the - still in beta - new API for Nexus. It's available by default on the version 3.3.0 and more: http://localhost:8082/swagger-ui/
Basically, you retrieve the json output from this URL: http://localhost:8082/service/siesta/rest/beta/assets?repositoryId=YOURREPO
Only 10 records will be displayed at a time and you will have to use the continuationToken provided to request the next 10 records for your repository by calling: http://localhost:8082/service/siesta/rest/beta/assets?continuationToken=46525652a978be9a87aa345bdb627d12&repositoryId=YOURREPO
More information here: http://blog.sonatype.com/nexus-repository-new-beta-rest-api-for-content

Spring MVC - respecting double slash in REST request

Lets say I have the following two REST endpoints built with Spring MVC (v.4):
1. [GET] /cars/make/{make}
2. [GET] /cars/make/{make}/model
And the following requests:
1. curl -X GET -H "Accept: application/json" "http://localhost/cars/make//model"
2. curl -X GET -H "Accept: application/json" "http://localhost/cars/make/%20/model"
The two requests will match the first endpoint (with path variable make having a value of model. Is it possible to change the matcher to match on the second endpoint with make being an empty string or whitespace?
I've been able to override the default Spring AntPathMatcher to not trim tokens, thus fixing the issue with the second request. However I'm not sure how to modify it so that it strictly respects the 2 backslashes with no whitespace in between. Is this possible?