---
title: HTTP methods
description: Configure GET and POST for SPARQL requests
---

import { Aside } from '@astrojs/starlight/components';

sparqlite supports both GET and POST HTTP methods for SPARQL requests, following the SPARQL 1.1 Protocol specification.

## Default methods

Each query type uses a default HTTP method:

| Query type | Default method | Reason |
|------------|---------------|--------|
| SELECT | GET | Read operation, cacheable |
| ASK | GET | Read operation, cacheable |
| CONSTRUCT | GET | Read operation, cacheable |
| DESCRIBE | GET | Read operation, cacheable |
| UPDATE | POST | Write operation (required by spec) |

GET requests pass the query as a URL parameter (`?query=...`). POST requests pass the query in the request body as form-encoded data.

## Overriding the default method

All read query methods accept a `method` keyword argument:

```python
from sparqlite import SPARQLClient

with SPARQLClient("https://opencitations.net/meta/sparql") as client:
    # Use POST for a long SELECT query that may exceed URL length limits
    result = client.query(long_query, method="POST")

    # Use POST for ASK
    exists = client.ask(query, method="POST")

    # Use POST for CONSTRUCT
    triples = client.construct(query, method="POST")

    # Use POST for DESCRIBE
    data = client.describe(query, method="POST")
```

<Aside type="note">
  The `update()` method always uses POST. The SPARQL 1.1 Protocol specification requires POST for update operations.
</Aside>

## When to use POST for read queries

Use `method="POST"` when:

- The query string is very long and may exceed URL length limits (typically 2000-8000 characters depending on the server)
- You want to avoid caching of results

```python
with SPARQLClient("https://opencitations.net/meta/sparql") as client:
    long_query = "SELECT * WHERE { " + " UNION ".join(
        f"{{ ?s <http://example.org/p{i}> ?o }}" for i in range(100)
    ) + " }"

    # POST avoids URL length issues
    result = client.query(long_query, method="POST")
```