Creating HTTP Connections Programmatically
Step-by-step guide to connecting to external APIs using HTTP endpoints
This guide demonstrates how to programmatically create and execute HTTP connections using the Infactory API.
Overview
When creating an HTTP connection, the process involves:
- Testing the connection to verify the API endpoint works
- Creating a datasource to store connection information
- Setting up credentials for authentication
- Executing the request to establish the connection and load data
Behind the scenes, this process creates:
- A datasource record in the database
- A data object for the HTTP request configuration
- A data object for the response data (in parquet format)
- Data lineage records connecting these objects
Prerequisites
- Authentication token or session cookie
- Project ID where you want to create the connection
- API endpoint URL you want to connect to
Step 1: Test the HTTP Connection
First, test that your API endpoint is accessible and returns the expected data:
Request Parameters:
url
: The API endpoint URLmethod
: HTTP method (GET, POST, PUT, etc.)headers
: HTTP headers to include with the requestparameters
: Query parameters with values and required flagsparameterGroups
: Groups of related parameters (optional)authType
: Authentication type (None, API Key, Bearer Token, Basic Auth)auth
: Authentication details based on the auth typeresponsePathExtractor
: JSON path to extract a specific key from the response (e.g., “value”)
Response:
Step 2: Create a Datasource
Create a datasource to store your HTTP connection data:
Request Parameters:
name
: Name of the datasourceproject_id
: ID of the project to associate withtype
: Must be “http-requests” for HTTP connectionsstatus
: Initial status (typically “transformation_started”)
Response:
Save the returned id
as your datasource_id
for the next steps.
Step 3: Create Credentials
Create credentials to store connection details and authentication information:
Request Parameters:
name
: Name for the credentialstype
: “api” for API credentialsdescription
: Description of what the credentials are formetadata
: Additional information about the APIdatasource_id
: ID of the datasource from step 2team_id
: Team that can access these credentialsorganization_id
: Organization that owns these credentialsconfig
: Configuration details for the connection
Step 4: Execute the HTTP Request
Finally, execute the HTTP request to establish the connection and load data:
Request Parameters:
- HTTP connection details (same as test-connection)
project_id
: ID of the projectdatasource_id
: ID of the datasource created in step 2connect_spec
: Connection specification object with:name
: Name of the connectionid
: Type identifier (“http-requests”)config
: Full configuration matching the test-connection parameters
Response:
What Happens Behind the Scenes
When you execute this flow:
- The system creates a data object to store your HTTP request configuration
- It executes the HTTP request and fetches data from the API
- The response is converted to a Parquet file and stored as another data object
- Data lineage is established between request and response data objects
- Background jobs analyze the data structure and prepare it for querying
- The system automatically generates query programs based on the data structure
- These query programs are ready to use immediately without manual coding
Automatic Query Generation
One of the powerful features of this process is that the system automatically creates query programs (ready-to-use queries) based on the API response data. This means:
- You don’t need to manually write queries to explore the API data
- The system examines the structure and content of the API response
- It generates relevant queries tailored to the specific data received
- These queries are immediately available in your project for use
- You can execute or modify these generated queries as needed
This automatic query generation significantly accelerates the time from connection to insight, allowing you to start working with the API data immediately after establishing the connection.
Code Example (Python)
Here’s a complete Python example showing all steps:
Now the HTTP connection is established and the data is available in your project.