Skip to content

Commit

Permalink
feat(lapis2-docs): document url encoded forms
Browse files Browse the repository at this point in the history
resolves #765
  • Loading branch information
fengelniederhammer committed Apr 30, 2024
1 parent f2f62b1 commit 882d183
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lapis2-docs/src/components/RenderedExampleForm.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
import { getConfig } from '../config';
import { getLapisUrl } from '../lapisUrl';
const firstMetadatum = getConfig().schema.metadata[0];
const lapisUrl = getLapisUrl();
const html = String.raw`<form action="${lapisUrl}/sample/aggregated" method="POST">
<label>
Field to aggregate by:
<input type="text" name="fields" value="${firstMetadatum.name}" />
</label>
<input type="hidden" name="downloadAsFile" value="true" />
<input type="submit" value="Submit" />
</form>`;
---

<pre><code>{html}</code></pre>

<div set:html={html} />
17 changes: 17 additions & 0 deletions lapis2-docs/src/content/docs/concepts/request-methods.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ description: Request methods

import TabsBox from '../../../components/TabsBox/astro/TabsBox.astro';
import Tab from '../../../components/TabsBox/astro/Tab.astro';
import RenderedExampleForm from '../../../components/RenderedExampleForm.astro';

LAPIS supports queries via GET and POST requests. GET requests encode the query in the URL, offering a simple, shareable
format ideal for direct browser access. Most features are supported with GET requests. POST requests requires formatting
Expand Down Expand Up @@ -57,3 +58,19 @@ example code for doing it with curl and from R and Python:
This is a general example and will only work on instances that have the fields `region`, `country`, and `date`.
Check out the [fields](../references/fields/) and [filters](../references/filters/) page to see information about this instance.
:::

## URL Encoded Form Data

LAPIS also supports [URL encoded form data](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST) for POST requests.
The content type must be set to `application/x-www-form-urlencoded` and the query must be encoded as a query string.

:::tip
This is useful if you want to send the query directly from a HTML form.
If `<form>` element has the `method` attribute set to `POST`
and the `enctype` attribute set to `application/x-www-form-urlencoded` (which is the default value),
then the `<form>` element will send the data as URL encoded form data.
:::

### Example

<RenderedExampleForm />

0 comments on commit 882d183

Please sign in to comment.