Quickstart: build a social media post generator as a REST API

Build a two-step Flow that fetches website content and generates social media posts. Attach the Flow to a Product and expose it through a REST API Surface.

Before you begin, review What are Flows?, What are Products?, and What are Surfaces?.

Before you begin

Sign in to the Runtype dashboard. Firecrawl is available through platform keys, so you do not need to add a provider API key for this quickstart.

What you build

You build a Flow that fetches article content and generates three social media posts. You then attach the Flow to a Product and call it through a REST API Surface.

Create a flow

To create the Flow, follow these steps:

  1. On the Flows page, click Create Flow.
  2. Select Start from scratch.
  3. Add a step with the + control.
  4. Select Fetch URL.
  5. In the Fetch selector, select Firecrawl (Web Scraping).
  6. In the from URL field, enter {{website}}. When you run the Flow, enter a value for website.
  7. Add another step with the + control.
  8. Select Run Task.
  9. In the User editor, paste the following prompt:
Prompt
Here is website content:
{{fetch_result}}
Generate three social media posts for this article. Return a JSON object with these keys:
- "twitter" (under 280 characters)
- "linkedin" (2 to 3 paragraphs, professional tone)
- "instagram" (casual, with emoji suggestions)
  1. Set the Flow name to Website Content to Social Media Content.
  2. Click Create.

Flow variables use double curly braces. The {{website}} expression reads the input named website, and {{fetch_result}} reads the output from the Fetch URL step. The Fetch URL step uses fetch_result as its default output variable. If you change that output variable, update the expression in the prompt.

For more information, read Flow variables and templates.

Test the flow

To test the Flow before you create the Product, follow these steps:

  1. On the Flow editor, click Run flow.
  2. In Input Variables, enter https://example.com as the value for website.
  3. Click Run Flow.
  4. Confirm that the response contains posts for Twitter, LinkedIn, and Instagram.

If the response does not contain all three posts, return to the Run Task step, edit the prompt, and run the Flow again.

Create a Product and a Surface

A Product groups related Flows and Agents. A Capability makes a Flow or Agent available on a Product. A Surface exposes the Product through an interface, such as a REST API.

To create the Product and attach your Flow, follow these steps:

  1. On the Products page, click New product.
  2. Select REST API.
  3. In the Name field, enter Social Media Post Generator.
  4. Under Add a capability to power your REST API, select Use Existing.
  5. Select Flows.
  6. Select Website Content to Social Media Content.
  7. Click Create REST API.

The Product includes your Flow as a Capability and a REST API Surface. The Product editor opens with the Surface panel open.

Call the endpoint

Open the Product editor and copy the endpoint URL and API key from the REST API Surface. API Surface keys use the papi_ prefix.

Send a POST request to the capability-specific endpoint. The following TypeScript example sends the website input:

TypeScript
1const endpoint =
2 'https://api.runtype.com/v1/products/YOUR_PRODUCT_ID/surfaces/YOUR_SURFACE_ID/api/YOUR_CAPABILITY_SLUG'
3
4const response = await fetch(endpoint, {
5 method: 'POST',
6 headers: {
7 Authorization: 'Bearer YOUR_SURFACE_API_KEY',
8 'Content-Type': 'application/json',
9 },
10 body: JSON.stringify({
11 website: 'https://example.com',
12 }),
13})
14
15const data = await response.json()
16console.log(data)

Use the following cURL command to send the same request:

cURL
$curl -X POST \
> 'https://api.runtype.com/v1/products/YOUR_PRODUCT_ID/surfaces/YOUR_SURFACE_ID/api/YOUR_CAPABILITY_SLUG' \
> -H 'Authorization: Bearer YOUR_SURFACE_API_KEY' \
> -H 'Content-Type: application/json' \
> -d '{
> "website": "https://example.com"
> }'

Replace the following placeholders in both examples:

  • YOUR_PRODUCT_ID: the Product ID in the endpoint URL
  • YOUR_SURFACE_ID: the Surface ID in the endpoint URL
  • YOUR_CAPABILITY_SLUG: the URL-safe slug for the Flow Capability
  • YOUR_SURFACE_API_KEY: the full API key from the REST API Surface

The endpoint passes the request body directly to the Capability as input. Review the JSON response to confirm that the Flow returns the generated social media posts.

Next steps

Continue with these guides: