davidradl commented on code in PR #30: URL: https://github.com/apache/flink-connector-http/pull/30#discussion_r2945998276
########## docs/content/docs/connectors/table/http.md: ########## @@ -73,6 +73,119 @@ The HTTP source connector supports [Lookup Joins](https://nightlies.apache.org/f * [Logging the HTTP content](#logging-the-http-content) * [Restrictions at this time](#restrictions-at-this-time) <!-- TOC --> +## Quick Start + +This guide provides quick examples to get started with the HTTP connector. + +### SQL Example — HTTP Sink + +Use the HTTP Sink connector to write Flink records to an external HTTP endpoint via SQL: + +```sql +CREATE TABLE http_sink ( + id BIGINT, + name STRING, + status STRING +) WITH ( + 'connector' = 'http-sink', + 'url' = 'https://api.example.com/events', + 'format' = 'json', + 'insert-method' = 'POST' +); + +INSERT INTO http_sink SELECT id, name, status FROM source_table; +``` + +Note: Flink SQL uses single quotes for string literals in WITH clause options. + +### SQL Example — HTTP Lookup Source + +Use the HTTP Lookup connector to enrich a stream with data from an external HTTP API: + +```sql +-- Define the HTTP lookup table +CREATE TABLE http_lookup ( + id STRING, + payload STRING +) WITH ( + 'connector' = 'rest-lookup', + 'url' = 'https://api.example.com/data', + 'format' = 'json', + 'lookup-method' = 'GET' +); + +-- Enrich a stream using a lookup join +SELECT s.event_id, h.payload +FROM stream_table AS s +JOIN http_lookup FOR SYSTEM_TIME AS OF s.proc_time AS h + ON s.event_id = h.id; +``` + +### DataStream API Example — HTTP Sink + +Use the HTTP Sink connector in the Flink DataStream API: + +```java +import org.apache.flink.connector.http.HttpSink; +import org.apache.flink.connector.http.sink.HttpSinkRequestEntry; +import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; +import org.apache.flink.streaming.api.datastream.DataStream; + +import java.nio.charset.StandardCharsets; + +public class HttpSinkExample { + public static void main(String[] args) throws Exception { + StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); + + // Create a simple source stream + DataStream<String> sourceStream = env.fromElements("event1", "event2", "event3"); + + // Configure the HTTP sink + HttpSink<String> httpSink = HttpSink.<String>builder() + .setEndpointUrl("https://api.example.com/events") + .setElementConverter( + (element, context) -> + new HttpSinkRequestEntry("POST", element.getBytes(StandardCharsets.UTF_8))) + .build(); + + // Send the source stream to the HTTP sink + sourceStream.sinkTo(httpSink); + + // Execute the Flink job + env.execute("HTTP Sink Example"); + } +} +``` + +### Common Configuration Options + +| Option | Required | Default | Description | +|---------------------------------------------|----------|---------|------------------------------------------------------------------------| +| `connector` | required | — | Use `http-sink` for sink or `rest-lookup` for lookup source. | Review Comment: not correct for the apache connector. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
