OpenLink Virtuoso Facets Webservice: post JSON-formatted query, request output in JSON - faceted-search

OpenLink Virtuoso Faceted Browser package provides both a user interface, and a web service (Faceted Browsing Service) for faceted search against a Virtuoso triple store. The service is described on their website.
According to the documentation, the service "takes an XML or JSON description of the desired view (via HTTP POST), and generates the reply in the form of XML or JSON documents comprised of the requested data".
The documentation has plenty of examples of sending requests and receiving responses in the XML format, which I was able to reproduce successfully and run against my local installation of Virtuoso. However, there are no examples with queries and responses encoded in JSON.
I can probably dissect the Faceted Browser source code (can be found in github) and figure out how to format the queries as JSON and force the service to return JSON output instead of XML, but perhaps someone has already done that and can post a couple of working examples with JSON input/output here.
Also, for the XML-formatted queries and responses, are there links to corresponding XML Schema Definition files somewhere in the documentation? I could not find them.

Related

How to use REST API with FaunaDB?

I have created a collection in my Fauna database. I also made an index that returns all the data in that collection. I want to know if there is a way to get JSON REST API to work with this data. What I mean by this is I want a URL that I can 'GET' using XMLHttpRequest and then parse into JSON.
You might say that Fauna is "HTTP native". All of the language drivers (JS, C#, Python, etc.) are built on top of http requests. That is, there are no special connections or connection-pools to maintain. You can get pretty far with using the JS driver in the browser, for example, without using a server.
But to answer your question more directly, there are many ways to serve a REST API, and it is going to depend on how you want to serve the API.
Examples
AWS
Here is a blog post on how to set up a REST API with AWS App Runner, for example.
https://fauna.com/blog/deploying-a-rest-api-with-aws-app-runner-and-fauna
Vercel and Netlify
There are also some example apps on github that demonstrate using a REST API with
Vercel:
https://github.com/vercel/next.js/tree/canary/examples/with-cookie-auth-fauna
Or Netlify:
https://github.com/netlify/netlify-faunadb-example
Both of which host serverless functions for you to create a REST API.

Download different content types with spring

I need to expose a POST endpoint where the user uploads an excel file and based on some validations, I either send back the file with some information added to it along with json response OR just send status code as 200 OK(no data).
I am trying to do this in spring boot. I tried following link:
https://javadigest.wordpress.com/2012/02/13/downloading-multiple-files-using-multipart-response/
This works but needs adding boundary manually. Is there any other way to do it so that I can send both the data ?
You should use #Produces as it is written here: https://docs.oracle.com/cd/E19776-01/820-4867/ghrpv/index.html
You can define the MIME-Type of your payload.

How Should I Make Spring Boot Rest API's Return Response in Client Requested Formate

I have Spring boot Rest APIS, but i want make those APIS Response as per the Client Requested Format.
For Instance :
Rest APIS Return Response By default In Json format. But Client Want to in XML formate or any other formate.
In the above situation how can i make my APIS dynamically Retunr the Response as per the Client requested format.
can any tell how can i do this.
Thanks in advance.
What you are talking about is Content Negotiation - Here's a Baeldung article that describes how you might use Jackson libraries to handle both XML and JSON data,
https://www.baeldung.com/spring-mvc-content-negotiation-json-xml
You need to devise a content negotiation strategy - very often, that is the use of the Accept header. Your API then has to respect this header and return the appropriate content, which might mean your API contracts having certain attributes to allow it to easily serialize to JSON/XML.
The article linked above links to a github repo that shows how this might be achieved - https://github.com/eugenp/tutorials/tree/master/spring-mvc-basics

BubbleWrap HTTP get request

I have an app that I am trying to pull data from a remote database. I have the url and the table columns and database name but i'm not sure how to call on that database with an http get. Below is my code:
def self.data
BubbleWrap::HTTP.get("url", {credentials: {username: '***', password: '***'}}) do |response|
p response.to_s
end
end
I know this request is working because it shows me data in the console.I can't find anywhere how to request information from a database attached that url. Any help would be greatly appreciated. I have been working with Ruby for a year now but new to RubyMotion.
Not sure to understand exactly your question, but you might want to take a look at this link and this one, explaining how to retrieve and handle data from a service.
Hope it helps.
This may be too elementary, but with an HTTP request you are not querying a database, you are requesting data from an HTTP server. It's the job of the server to look your request over, go to the database, retrieve the data, package it (often in JSON format), and ship it back. I believe that's what #railsdog was referring to in terms of marshaling.
Now, a couple of other comments:
"url" in your code should be an actual endpoint like https://my.server.org/api/some_endpoint.json. The payload containing credentials can be attached as a query string, however, you might want to consider POST and SSL, as I say in my next point.
You should never send credentials in clear text over HTTP. If you have to send sensitive information, use HTTPS (set up your server to respond to SSL-encrypted requests).
It's probably best to authenticate once on first request and get a token you can use on subsequent requests so as not to expose usernames and passwords unduly. Perhaps you can fill in a few blanks about what your server is (Rails, some public API, other) and it will make it easier to help.
You will need to accept the data from the server in some recognizable format. JSON is very well supported. BubbleWrap has a JSON parser to help turn the results into a hash. Alternate formats are XML (ick) or XML-RPC (ick, ick), or SOAP (ick, ick, ice).
If you're way ahead of me on this and it's too basic to be of use, I apologize.

Preventing bad data insertion in Node with NoSQL Database

Let's say we have a simple node JS backend, paired with a standard NoSQL document store such as CouchDB. Since our database is just a document key-store with no schema, anything can get inserted. And since our server is built on JSON as well, ultimately POST requests that come in from the client with JSON payloads end up getting stored directly into our data store.
This of course is very convenient and makes for a lightweight application. I've been wondering, though, short of writing code for every possible insertion endpoint to verify that each POST or PUT request is well-formed, is there anything to prevent an attacker from firing up their developer console and spoofing POST/PUT requests, allowing them to insert any kind of junk data they wish into our datastore? It would not be too difficult to wreck an application's data this way.
Clearly token-based authentication can ensure that only authenticated users can access these service endpoints, but that doesn't prevent them from spoofing these request with the same HTTP headers that valid requests have. This is all quite simple with today's browser developer tools.
In a traditional server language like Java, JSON PUTs and POSTs are marshalled to a highly-structured class-based Object. Requests whose payloads do NOT match these formats are rejected with HTTP errors.
Does anyone know of tools or paradigms for node which ensures that requests like this meet some basic structure criteria?

Resources