Show HN: Jam API, turn any site into a JSON api using CSS selectors

Jam API is a service that allows you to turn any site into a JSON accessible api using CSS selectors. To get started simply run a post request to http://www.jamapi.xyz with formdata of “url” and “json_data”, here’s an example of what your data should look like (you can also play around with the api in action with this form, this queries the homepage of Radcircle of their most recent articles, getting the title of the article and the permalink to the article):

Code Examples

Node.js

const request = require('request');
request.post('http://www.jamapi.xyz/', {form: {url: 'http://www.radcircle.com', json_data: '{"title": "title"}'}}, function(err, response, body) {
  console.log(body); // Return the title from http://www.radcircle.com
})  

Ruby

require 'httparty'
require 'json'
response = HTTParty.post("https://www.jamapi.xyz/",
{ 
  :body => [ { "url" => "http://www.radcircle.com", "json_data" => "{'title': 'title'}"} ].to_json,
  :headers => { 'Content-Type' => 'application/json', 'Accept' => 'application/json'}
})  
puts JSON.parse(response)

Features

Will auto pull the img src on corresponding elements, will auto pull the href from links. If passing JSON, you must provide a “elem” property, and then the element attributes you want. When you pass an array with JSON you’ll get a structure that looks as follows:

[
  {
      "index": 0,
      "value": {
          "value": "Porter Robinson – Sad Machine (Cosmo’s Midnight Remix)"
      }
  },
  {
      "index": 1,
      "value": {
          "value": "Listen to Rachel Platten’s “Stand By You”"
      }
  }]

All the attributes you provide as JSON will be put inside of the value property, and the index property is to be able to track what index it ocurred in the DOM. I nested JSON values into it’s own so that you can still have an “index” property returned and not run into issues.


Original URL: http://feedproxy.google.com/~r/feedsapi/BwPx/~3/HS1Xj73xCK4/

Original article

Comments are closed.

Proudly powered by WordPress | Theme: Baskerville 2 by Anders Noren.

Up ↑

%d bloggers like this: