SDKs overview
Product Hunt provides SDKs and libraries to facilitate developer interaction with its platform, primarily through its GraphQL API. These SDKs are designed to abstract away the complexities of making direct HTTP requests and managing OAuth2 authentication, allowing developers to focus on building applications that integrate with Product Hunt's ecosystem. The API supports queries for retrieving product information, user data, and community interactions, enabling custom tools, analytics dashboards, or integrations with other services.
The developer experience with Product Hunt's API is shaped by its GraphQL foundation. This enables clients to request precisely the data they need, thereby reducing over-fetching or under-fetching of data, common issues with traditional REST APIs (GraphQL.org documentation). Developers can construct complex queries to retrieve nested resources in a single request, which can optimize performance and simplify client-side data handling. Basic rate limits are applied, with options for higher limits based on specific application requirements.
Official SDKs by language
Product Hunt maintains official SDKs for popular programming languages, providing tested and supported methods for integrating with their API. These SDKs typically handle client-side GraphQL query construction, request signing, and response parsing, streamlining development workflows. The official offerings focus on languages commonly used in web and backend development.
| Language | Package Name | Installation Command | Maturity | Documentation Link |
|---|---|---|---|---|
| Ruby | producthunt-ruby |
gem install producthunt-ruby |
Stable | Product Hunt Help Center |
| Node.js | producthunt |
npm install producthunt |
Stable | Product Hunt Help Center |
Installation
Installation of Product Hunt SDKs generally follows the standard package management practices for each respective language. These commands retrieve the necessary libraries and dependencies, making them available in your project environment.
Ruby SDK Installation
To integrate the Product Hunt Ruby SDK into a Ruby project, you can use the Bundler dependency manager or install the gem directly.
# Using Bundler (recommended for most projects)
gem 'producthunt-ruby'
# Then, run:
bundle install
# Direct gem installation
gem install producthunt-ruby
Node.js SDK Installation
For Node.js projects, the SDK is installed via npm (Node Package Manager) or yarn.
# Using npm
npm install producthunt
# Using yarn
yarn add producthunt
Quickstart example
The following examples demonstrate how to make a basic API call using the official SDKs to fetch data, such as a list of upcoming products. Prior to running these examples, ensure you have obtained an OAuth2 access token from Product Hunt, which is necessary for authenticated requests (Product Hunt authentication details).
Ruby Quickstart
This Ruby example initializes the client with an access token and queries for the first five upcoming products.
require 'producthunt-ruby'
# Replace with your actual OAuth2 access token
ACCESS_TOKEN = 'YOUR_PRODUCT_HUNT_ACCESS_TOKEN'
client = ProductHunt::Client.new(token: ACCESS_TOKEN)
query = <<-GRAPHQL
query {
upcomingProducts(first: 5) {
edges {
node {
name
tagline
url
}
}
}
}
GRAPHQL
begin
response = client.query(query: query)
if response.data
puts "Upcoming Products:"
response.data.upcomingProducts.edges.each do |edge|
product = edge.node
puts "- Name: #{product.name}"
puts " Tagline: #{product.tagline}"
puts " URL: #{product.url}"
end
elsif response.errors
puts "GraphQL Errors:"
response.errors.each { |error| puts "- #{error['message']}" }
end
rescue ProductHunt::Error => e
puts "API Error: #{e.message}"
end
Node.js Quickstart
This Node.js example uses the producthunt package to fetch details for the first five upcoming products.
const { Client } = require('producthunt');
// Replace with your actual OAuth2 access token
const ACCESS_TOKEN = 'YOUR_PRODUCT_HUNT_ACCESS_TOKEN';
const client = new Client({ accessToken: ACCESS_TOKEN });
const query = `
query {
upcomingProducts(first: 5) {
edges {
node {
name
tagline
url
}
}
}
}
`;
(async () => {
try {
const response = await client.request(query);
if (response.data) {
console.log('Upcoming Products:');
response.data.upcomingProducts.edges.forEach(edge => {
const product = edge.node;
console.log(`- Name: ${product.name}`);
console.log(` Tagline: ${product.tagline}`);
console.log(` URL: ${product.url}`);
});
} else if (response.errors) {
console.error('GraphQL Errors:');
response.errors.forEach(error => console.error(`- ${error.message}`));
}
} catch (error) {
console.error('API Error:', error.message);
}
})();
Community libraries
In addition to the official SDKs, the Product Hunt developer community contributes libraries in various programming languages. These community-maintained libraries extend the reach of Product Hunt's API to other environments and often provide alternative approaches or specialized functionalities. While not officially supported by Product Hunt, they can be valuable resources for developers working in specific tech stacks.
Python Libraries
Product Hunt's GraphQL API can be accessed from Python using popular GraphQL client libraries. While there is no single 'official' Python SDK, developers commonly use generic GraphQL clients or build custom wrappers. A widely used generic GraphQL client is sgqlc, which aids in constructing and executing GraphQL queries (Google Developers GraphQL best practices).
Installing a Generic GraphQL Client for Python
To interact with the Product Hunt API from Python, you can install a GraphQL client like requests-graphql or `GQL`.
pip install requests-graphql
# or
pip install gql
Python Quickstart with requests-graphql
This example demonstrates how to use the requests-graphql library to query the Product Hunt API for upcoming products.
import os
from requests_graphql import GraphQLSession
# Replace with your actual OAuth2 access token
ACCESS_TOKEN = os.environ.get('PRODUCT_HUNT_ACCESS_TOKEN', 'YOUR_PRODUCT_HUNT_ACCESS_TOKEN')
API_URL = 'https://api.producthunt.com/v2/api/graphql'
headers = {
'Authorization': f'Bearer {ACCESS_TOKEN}',
}
session = GraphQLSession(graphql_url=API_URL, headers=headers)
query = '''
query {
upcomingProducts(first: 5) {
edges {
node {
name
tagline
url
}
}
}
}
'''
try:
response = session.query(query)
if 'data' in response:
print('Upcoming Products:')
for edge in response['data']['upcomingProducts']['edges']:
product = edge['node']
print(f"- Name: {product['name']}")
print(f" Tagline: {product['tagline']}")
print(f" URL: {product['url']}")
elif 'errors' in response:
print('GraphQL Errors:')
for error in response['errors']:
print(f"- {error['message']}")
except Exception as e:
print(f"API Error: {e}")
When using community libraries or generic GraphQL clients, developers should consult the specific library's documentation for detailed usage instructions and consider the maintenance status of the project. These alternatives can offer flexibility for projects not directly supported by official SDKs (Product Hunt developer resources).