# Quickstart: send your first HTTP task

> Get started with pushq in five minutes. Create an API key, create a queue, enqueue an HTTP task and receive it on your endpoint with signature checks.

Source: https://pushqueue.dev/docs/getting-started/quickstart/

This quickstart takes you from zero to a delivered task with the hosted pushq API at `https://api.pushqueue.dev`: you create an API key, create a queue, enqueue an HTTP task and receive it on your own endpoint. Every step works the same against a server you run yourself; to try pushq on your machine without an account, see [local development with `pushq dev`](https://pushqueue.dev/docs/getting-started/local-development/).

## Create an API key

Sign in to the [pushq console](https://console.pushqueue.dev/) and create a key under **Settings → API keys**. The key is shown once, so store it as an environment variable:

```bash
export PUSHQ_API_KEY="pq_..."
```

Every request sends it as a bearer token (`Authorization: Bearer pq_...`). [API keys](https://pushqueue.dev/docs/guides/api-keys/) explains roles, rotation and revocation.

## Install an SDK

Pick your language. Every SDK talks to the hosted API by default, and the docs remember the language you pick.


**TypeScript**

```bash
npm install pushq
```

**Python**

```bash
pip install pushq
```

**Go**

```bash
go get github.com/blissfulrays/pushq/sdks/go
```

**Java**

```xml
<!-- Not on Maven Central yet: build it with `mvn install` in sdks/java first. -->
<dependency>
  <groupId>io.github.blissfulrays</groupId>
  <artifactId>pushq</artifactId>
  <version>1.0.0-SNAPSHOT</version>
</dependency>
```

**.NET**

```bash
dotnet add package Pushq
```

**curl**

```bash
# No install needed: call the REST API directly.
curl https://api.pushqueue.dev/v1/version -H "Authorization: Bearer $PUSHQ_API_KEY"
```

[Install & configure an SDK](https://pushqueue.dev/docs/getting-started/sdks/) covers client options, errors and versions for each language.

## Create a client


**TypeScript**

```ts

const pq = new Pushq({ apiKey: process.env.PUSHQ_API_KEY });
```

**Python**

```python
import os
from pushq import Pushq

pq = Pushq(api_key=os.environ["PUSHQ_API_KEY"])
```

**Go**

```go
import (
	"context"
	"os"

	pushq "github.com/blissfulrays/pushq/sdks/go"
)

pq := pushq.New("", os.Getenv("PUSHQ_API_KEY")) // "" = https://api.pushqueue.dev
ctx := context.Background()
```

**Java**

```java
import io.pushq.*;

Pushq pq = Pushq.builder()
    .apiKey(System.getenv("PUSHQ_API_KEY"))
    .build();
```

**.NET**

```csharp
using Pushq;

using var pq = new PushqClient(apiKey: Environment.GetEnvironmentVariable("PUSHQ_API_KEY"));
```

**curl**

```bash
export PUSHQ_URL="https://api.pushqueue.dev"
```

## Create a queue

A queue holds tasks and says where to deliver them and how fast. This one delivers to `https://api.example.com` at up to 10 requests per second, 5 at a time, and signs every delivery.


**TypeScript**

```ts
await pq.upsertQueue("emails", {
  rateLimits: { maxDispatchesPerSecond: 10, maxConcurrentDispatches: 5 },
  target: { baseUrl: "https://api.example.com", signingSecret: process.env.PUSHQ_SIGNING_SECRET },
});
```

**Python**

```python
from pushq import RateLimits, Target

pq.upsert_queue(
    "emails",
    rate_limits=RateLimits(max_dispatches_per_second=10, max_concurrent_dispatches=5),
    target=Target(base_url="https://api.example.com", signing_secret=os.environ["PUSHQ_SIGNING_SECRET"]),
)
```

**Go**

```go
_, err := pq.UpsertQueue(ctx, "emails", pushq.QueueConfig{
	RateLimits: &pushq.RateLimits{
		MaxDispatchesPerSecond:  pushq.Float64(10),
		MaxConcurrentDispatches: pushq.Int(5),
	},
	Target: &pushq.Target{
		BaseURL:       "https://api.example.com",
		SigningSecret: os.Getenv("PUSHQ_SIGNING_SECRET"),
	},
})
```

**Java**

```java
pq.upsertQueue("emails", QueueConfig.builder()
    .rateLimits(RateLimits.builder()
        .maxDispatchesPerSecond(10)
        .maxConcurrentDispatches(5)
        .build())
    .target(Target.builder()
        .baseUrl("https://api.example.com")
        .signingSecret(System.getenv("PUSHQ_SIGNING_SECRET"))
        .build())
    .build());
```

**.NET**

```csharp
await pq.UpsertQueueAsync("emails", new QueueConfig
{
    RateLimits = new RateLimits { MaxDispatchesPerSecond = 10, MaxConcurrentDispatches = 5 },
    Target = new Target
    {
        BaseUrl = "https://api.example.com",
        SigningSecret = Environment.GetEnvironmentVariable("PUSHQ_SIGNING_SECRET"),
    },
});
```

**curl**

```bash
curl -X PUT "$PUSHQ_URL/v1/queues/emails" \
  -H "Authorization: Bearer $PUSHQ_API_KEY" \
  -d '{
    "rate_limits": {"max_dispatches_per_second": 10, "max_concurrent_dispatches": 5},
    "target": {"base_url": "https://api.example.com", "signing_secret": "whsec_..."}
  }'
```

:::caution[Upsert replaces the whole configuration]
Creating or updating a queue with upsert (`PUT`) replaces its configuration: any field you leave out goes back to its default, and only the signing secret is kept. Send the full configuration every time, or change single settings with a patch. See [queues](https://pushqueue.dev/docs/concepts/queues/).
:::

## Enqueue a task

A task is one HTTP request pushq makes for you. `path` is resolved against the queue's base URL, so this task becomes `POST https://api.example.com/hooks/send-welcome`, delivered in an hour.


**TypeScript**

```ts
await pq.createTask("emails", {
  taskId: "welcome-user-42",   // optional: a second create with this ID is rejected
  path: "/hooks/send-welcome",
  jsonBody: { user_id: 42 },
  delaySeconds: 3600,          // omit to deliver now
});
```

**Python**

```python
pq.create_task(
    "emails",
    task_id="welcome-user-42",
    path="/hooks/send-welcome",
    json_body={"user_id": 42},
    delay_seconds=3600,
)
```

**Go**

```go
_, err = pq.CreateTask(ctx, "emails", pushq.TaskCreate{
	TaskID:       "welcome-user-42",
	Path:         "/hooks/send-welcome",
	JSONBody:     map[string]any{"user_id": 42},
	DelaySeconds: pushq.Float64(3600),
})
```

**Java**

```java
pq.createTask("emails", TaskCreate.builder()
    .taskId("welcome-user-42")
    .path("/hooks/send-welcome")
    .jsonBody(Map.of("user_id", 42))
    .delaySeconds(3600)
    .build());
```

**.NET**

```csharp
await pq.CreateTaskAsync("emails", new TaskCreate
{
    TaskId = "welcome-user-42",
    Path = "/hooks/send-welcome",
    JsonBody = new Dictionary<string, object> { ["user_id"] = 42 },
    Delay = TimeSpan.FromHours(1),
});
```

**curl**

```bash
curl -X POST "$PUSHQ_URL/v1/queues/emails/tasks" \
  -H "Authorization: Bearer $PUSHQ_API_KEY" \
  -d '{"task_id": "welcome-user-42", "path": "/hooks/send-welcome", "json_body": {"user_id": 42}, "delay_seconds": 3600}'
```

A second create with the same `task_id` fails with `409 already_exists`, which makes enqueueing safe to retry. See [deduplicate tasks](https://pushqueue.dev/docs/patterns/deduplication/).

## Receive the task and verify its signature

pushq calls your endpoint with the task's body and `X-Pushq-*` headers. **Return any 2xx** to mark the task done; any other status, or a timeout, is retried with backoff. Because the queue has a signing secret, verify each delivery against the raw request body before trusting it:


**TypeScript**

```ts

const app = express();

// express.raw keeps the exact bytes; don't run express.json() on this route.
app.post("/hooks/send-welcome", express.raw({ type: "*/*" }), async (req, res) => {
  let webhookId: string;
  try {
    webhookId = await verifySignature({
      secret: process.env.PUSHQ_SIGNING_SECRET!,
      headers: req.headers,
      payload: req.body,
    });
  } catch (err) {
    if (err instanceof WebhookVerificationError) return res.status(401).end();
    throw err;
  }
  const { user_id } = JSON.parse(req.body.toString("utf8"));
  await sendWelcomeEmail(user_id, webhookId); // webhookId is stable across retries
  res.sendStatus(204);
});
```

**Python**

```python
import os
from fastapi import FastAPI, HTTPException, Request
from pushq import WebhookVerificationError, verify_signature

app = FastAPI()

@app.post("/hooks/send-welcome")
async def send_welcome(request: Request):
    body = await request.body()  # raw bytes, not parsed JSON
    try:
        webhook_id = verify_signature(os.environ["PUSHQ_SIGNING_SECRET"], request.headers, body)
    except WebhookVerificationError:
        raise HTTPException(status_code=401)
    # webhook_id ("emails/welcome-user-42") is stable across retries
    return {"ok": True}
```

**Go**

```go
func handleSendWelcome(w http.ResponseWriter, r *http.Request) {
	body, err := io.ReadAll(r.Body) // raw bytes, before any JSON decoding
	if err != nil {
		http.Error(w, "read error", http.StatusBadRequest)
		return
	}
	id, err := pushq.VerifySignature(os.Getenv("PUSHQ_SIGNING_SECRET"), r.Header, body, 5*time.Minute)
	if err != nil {
		http.Error(w, "invalid signature", http.StatusUnauthorized)
		return
	}
	_ = id // "emails/welcome-user-42", stable across retries
	w.WriteHeader(http.StatusNoContent)
}
```

**Java**

```java
@PostMapping("/hooks/send-welcome")
public ResponseEntity<Void> sendWelcome(@RequestBody byte[] payload,   // raw body, unparsed
                                        @RequestHeader("webhook-id") String id,
                                        @RequestHeader("webhook-timestamp") long ts,
                                        @RequestHeader("webhook-signature") String sig) {
    try {
        Webhooks.verifySignature(System.getenv("PUSHQ_SIGNING_SECRET"), id, ts, payload, sig, 300);
    } catch (WebhookVerificationException e) {
        return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build();
    }
    // trusted: parse the payload and do the work
    return ResponseEntity.ok().build();
}
```

**.NET**

```csharp
app.MapPost("/hooks/send-welcome", async (HttpRequest req) =>
{
    using var ms = new MemoryStream();
    await req.Body.CopyToAsync(ms);
    var body = ms.ToArray();
    try
    {
        // "emails/welcome-user-42": stable across retries
        string webhookId = Webhooks.VerifySignature(
            Environment.GetEnvironmentVariable("PUSHQ_SIGNING_SECRET")!,
            name => req.Headers[name].FirstOrDefault(),
            body);
        return Results.Ok();
    }
    catch (WebhookVerificationException)
    {
        return Results.Unauthorized();
    }
});
```

Delivery is at-least-once, so make the handler safe to run twice: the verified ID (`queue/task_id`) stays the same across retries and works as an idempotency key. See [delivery and signing](https://pushqueue.dev/docs/concepts/delivery/) and [idempotent handlers](https://pushqueue.dev/docs/patterns/idempotent-handlers/).

## Check the task's status and attempts

```bash
curl "$PUSHQ_URL/v1/queues/emails/stats" -H "Authorization: Bearer $PUSHQ_API_KEY"
curl "$PUSHQ_URL/v1/queues/emails/tasks/welcome-user-42/attempts" -H "Authorization: Bearer $PUSHQ_API_KEY"
```

Or open the [console](https://console.pushqueue.dev/) to see every queue with live stats and each task's attempt history.

## Read more

- [Queues](https://pushqueue.dev/docs/concepts/queues/): rate limits, concurrency, folders, pause and purge.
- [Tasks](https://pushqueue.dev/docs/concepts/tasks/): scheduling, deduplication and batch enqueue.
- [Retries and backoff](https://pushqueue.dev/docs/concepts/retries/): what happens when a delivery fails.
- [Rate limits](https://pushqueue.dev/docs/guides/rate-limits/): protect a downstream API.
- [Going to production](https://pushqueue.dev/docs/guides/going-to-production/): the checklist before you ship.
