A customizable, simple and easy to use json REST API consumer

Related tags

Web programming jack
Overview

JACK (JSON API Client Konsumer)

JACK is a generic JSON API client. It is useful to interact with APIs from multiple services such as Google and Twitter. All service along with their parameters are configured in config.toml file. For example, you can configure JACK to collect statistics from vairous social networks and Google Analytics, all from a single company/instituition.

Installing

JACK is written in Rust, so you need to install it first before compiling. Here's a few examples on how to install the Rust toolset:

Linux

Different Linux flavors provide different package managers. Here are few examples:

sudo apt install rust
sudo yum install rust

macOS

First, install Homebrew by following the instructions here. Then, open a terminal and use the brew command to install the Rust toolset:

brew install rust

Windows

Windows 11 comes with winget, a command-line package manager. You can open a Windows Terminal and type the following command:

winget install Rustlang.Rust.MSVC

If you don't have winget, you can either install it or download and install Rust from its the official website.

After Rust is intalled, clone JACK's repository and build it:

git clone https://github.com/mentebinaria/jack/
cd jack
cargo build

Configuration

Before running JACK, you have to configure your config.toml file. Here's how it works:

[some_api]
service_name = "Some API" # The name of the application
url = "http://someapi.xyz" # The url that it'll query
method = "GET" # The method to use (only GET for now)

[some_api.filter] # Optional
filter_name = "/field/item" # The filter is based on https://docs.serde.rs/serde_json/value/enum.Value.html#method.pointer
# ...

[some_api.params] # Optional
params = "value" # `?params=value` on GET requests
# ...

[some_api.oauth] # Optional
auth_uri = "https://some_api/oauth/auth"
token_uri = "https://some_api/oauth/token"
client_id = "Client ID" # Same reason why as the `client_secret`
client_secret = "Client SECRET" # Due the lack of a intermediate(private) server (maybe in the future...) containing the client_secret

YouTube API

Let's say you want some information about a certain YouTube channel. Start with creating a service in the config.toml file. Give preference to single words, but snake_case is allowed. As this service is a YouTube channel, you use the YouTube API in the url field:

[mychannel]
service_name = "Great YouTube Channel - YouTube Example"
url = "https://www.googleapis.com/youtube/v3/channels/"
method = "GET"

Now you have to tell JACK what kind of information you want to get from this channel. Available fields depend on the API. For YouTube API, they are documented here. Let's say we want title, contentDetails and statistics/viewCount. Here's how to configure them:

[mychannel.filter]
title = "/items/0/snippet/title"
contentDetails = "/items/0/contentDetails"
totalViews = "/items/0/statistics/viewCount"

Now you have to configure the parameters such as the desired YouTube channel ID you want to inspect, your API key and a few others. Here's an example with Papo Binário YouTube channel, whose ID is UCuQ8zW9VmVyml7KytSqJDzg:

[mychannel.params]
part = "snippet,contentDetails,statistics"
id = "UCuQ8zW9VmVyml7KytSqJDzg"
key = ""
maxResults = "50"

Done. When you run JACK with the above configuration, you should see the following output:

service_name = "Great YouTube Channel - YouTube Example"
contentDetails = {"relatedPlaylists":{"likes":"","uploads":"UUuQ8zW9VmVyml7KytSqJDzg"}}
title = "Papo Binário"
totalViews = "2083346"

YouTube Analytics API

For advanced metrics on YouTube, they offer separate service called YouTube Analytics. JACK can also interact with its API and perform OAuth authentication. Here's an example of configuration for getting the number of views, likes, subscribers gained, and the channel estimate minutes watched in January, 2021:

[mychannel_analytics]
service_name = "My Great Channel - YouTube Analytics Example"
url = "https://youtubeanalytics.googleapis.com/v2/reports"
method = "GET"

[youtube_analytics.filter]
views = "/rows/0/1"
likes = "/rows/0/2"
subscribersGained = "/rows/0/3"
estimatedMinutesWatched = "/rows/0/0"

[youtube_analytics.oauth]
auth_uri = "https://accounts.google.com/o/oauth2/auth"
token_uri = "https://oauth2.googleapis.com/token"
client_id = ""
client_secret = ""

[youtube_analytics.params]
ids = "channel==MINE"
metrics = "estimatedMinutesWatched,views,likes,subscribersGained"
startDate = "2021-01-01"
endDate = "2021-02-01"

Before running JACK with the above configuration, you need to provide a client_id and a client_secret for the YouTube Analytics API. Refer to this article if you don't have them yet.

JACK's output would be like the following:

service_name = "My Great Channel - YouTube Analytics Example"
estimatedMinutesWatched = 162626
likes = 2964
subscribersGained = 646
views = 37745

If you study the services' API enough, you'll be ready to use JACK to extract every possible bit of information you need. :)

Running

After you are finished with the configuration, you should be ready to run JACK as easy as:

cargo run
You might also like...
A pure Rust implementation of the Web Local Storage API, for use in non-browser contexts

Rust Web Local Storage API A Rust implementation of the Web LocalStorage API, for use in non-browser contexts About the Web Local Storage API MDN docs

Provides json/csv/protobuf streaming support for axum

axum streams for Rust Library provides HTTP response streaming support for axum web framework: JSON array stream format JSON lines stream format CSV s

This is a simple Api template for Rust ( Axum framework )

Axum-Rust-Rest-Api-Template This project is an open source Rest Api Template built with Rust's Axum framework. Why this project? I have been learning

Markdown LSP server for easy note-taking with cross-references and diagnostics.
Markdown LSP server for easy note-taking with cross-references and diagnostics.

Zeta Note is a language server that helps you write and manage notes. The primary focus is to support Zettelkasten-like1, 2 note taking by providing an easy way to cross-reference notes (see more about features below).

Discover GitHub token scope permission and return you an easy interface for checking token permission before querying GitHub.

github-scopes-rs Discover GitHub token scope permission and return you an easy interface for checking token permission before querying GitHub. In many

A super-easy, composable, web server framework for warp speeds.

warp A super-easy, composable, web server framework for warp speeds. The fundamental building block of warp is the Filter: they can be combined and co

A html document syntax and operation library written in Rust, use APIs similar to jQuery.

Visdom A server-side html document syntax and operation library written in Rust, it uses apis similar to jQuery, left off the parts thoes only worked

Rust I18n is use Rust codegen for load YAML file storage translations on compile time, and give you a t! macro for simply get translation texts.

Rust I18n Rust I18n is use Rust codegen for load YAML file storage translations on compile time, and give you a t! macro for simply get translation te

Starter template for use with the Leptos web framework and Axum.

Leptos Axum Starter Template This is a template for use with the Leptos web framework and the cargo-leptos tool using Axum. Creating your template rep

Owner
Mente Binária
Mente Binária
REST API server that abstracts the need to write CRUD methods by exposing a standardized API to interact with a Postgres database

Basiliq Exposing a Postgres database via a REST API that follows the JSON:API specs. All in all, a tasty API. What is Basiliq Quickstart Ready to use

Basiliq 54 Apr 21, 2022
Print Apple WeatherKit REST API weather conditions and hourly/daily foreacast to the console.

weatherkit-rust A Rust CLI program to print current conditions and daily/hourly forecast to the console. Please read authorization.md as you need an A

boB Rudis 11 Dec 23, 2022
Grape is a REST-like API framework for Ruby

Grape is a REST-like API framework for Ruby. It's designed to run on Rack or complement existing web application frameworks such as Rails and Sinatra by providing a simple DSL to easily develop RESTful APIs. It has built-in support for common conventions, including multiple formats, subdomain/prefix restriction, content negotiation, versioning and much more.

Ruby Grape 9.7k Jan 2, 2023
Rust Rest API Stack with User Management

A secure-by-default rest api stack implemented with hyper, tokio, bb8 and postgres. This project is focused on providing end-to-end encryption by default for 12-factor applications. Includes a working user management and authentication backend written in postgresql with async S3 uploading for POST-ed data files.

Jay 10 Dec 25, 2022
Rust Rocket MongoDB token-authorization REST API boilerplate

Rust Rocket MongoDB token-auth REST API boilerplate In this repository, you can find backend Rust rocket mongodb rest-api boilerplate with token autho

null 6 Dec 7, 2022
A highly customizable, full scale web backend for web-rwkv, built on axum with websocket protocol.

web-rwkv-axum A axum web backend for web-rwkv, built on websocket. Supports BNF-constrained grammar, CFG sampling, etc., all streamed over network. St

Li Junyu 12 Sep 25, 2023
A full-featured and easy-to-use web framework with the Rust programming language.

Poem Framework A program is like a poem, you cannot write a poem without writing it. --- Dijkstra A full-featured and easy-to-use web framework with t

Poem Web 2.2k Jan 6, 2023
Quick demo of a REST frontend with a Redis session store.

axum-rest-starter-example Important Tasks Ensure session UUID is unique Protect /api/ with JWT Add CSRF CORS? Dev Setup (1) Run docker compose up to f

Michael de Silva 23 Dec 31, 2022
A secure and efficient gateway for interacting with OpenAI's API, featuring load balancing, user request handling without individual API keys, and global access control.

OpenAI Hub OpenAI Hub is a comprehensive and robust tool designed to streamline and enhance your interaction with OpenAI's API. It features an innovat

Akase Cho 30 Jun 16, 2023
Proxies all incoming connections to a minecraft server of your choosing, while also logging all ping and login requests to a json file and discord webhook.

minecraft-honeypot Proxies all incoming connections to a minecraft server of your choosing, while also logging all ping and login requests to a json f

Cleo 19 Jan 4, 2023