🏠 back to Observable

How to use the POST method for getting data from API

Our database is behind a proxy server with an API to get to the data. We access it in web pages using an ajax call. Our Java applications access it in a similar way. The POST requires a body with two form fields.

In javascript we will do this like

var request = new FormData();
request.append(‘action’, ‘getRawSearchData’);
request.append(‘request’, params);

    type: "POST",
    url: "/solrproxy/servlet/searchApplet",
    data: request,

Can I use a similar method in a notebook to get our data?

The Javascript fetch function provides the ability to fetch a URL with a POST request:

And in a notebook, it’s as simple as Posting with Fetch / Mike Bostock / Observable. Mind you, your API will need to allow CORS for the browser to allow fetching from it.

mcmcclur & visnup,

Mucho thanks for help getting me there.

Getting CORS setup on my server was a bit of a pain, but all is well now!

I eventually ended up adding

<Location “/solrproxy/servlet/searchApplet”>
# CORS, cross origin resource request for ObservableHQ access
Header set Access-Control-Allow-Origin “*”
Header set Access-Control-Allow-Methods “PUT, GET, POST, OPTIONS”
Header set Access-Control-Allow-Headers "origin, x-requested-with, content-$

To limit the …Allow-Origin “*” to a specific domain for observable, what domain would be used?

thanks again,