Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add docs for supported langs #105

Merged
merged 2 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions astro.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,31 @@ export default defineConfig({
},
],
},
{
label: 'Supported Languages',
items: [
{
label: 'C++ client',
slug: 'clients/cpp',
},
{
label: 'Rust client',
slug: 'clients/rust',
},
{
label: 'Python client',
slug: 'clients/python',
},
{
label: 'Go client',
slug: 'clients/go',
},
{
label: 'LuaJIT client',
slug: 'clients/luajit',
},
],
},
],
}),
],
Expand Down
4 changes: 2 additions & 2 deletions astro/content/docs/cli/performance.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ compare against [trurl](https://github.com/curl/trurl) version 0.6 (libcurl/7.87

<details>
<summary>
**wikipedia_100k dataset**, adaparse can parse URLs **three times faster than trurl**.
wikipedia_100k dataset, adaparse can parse URLs three times faster than trurl.
</summary>

```bash
Expand All @@ -28,7 +28,7 @@ compare against [trurl](https://github.com/curl/trurl) version 0.6 (libcurl/7.87
</details>
<details>
<summary>
Using **top100 dataset**, adaparse is **twice as fast as the trurl**.
Using top100 dataset, adaparse is twice as fast as the trurl.
</summary>

```bash
Expand Down
147 changes: 147 additions & 0 deletions astro/content/docs/clients/cpp.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
---
title: C++
description: How to install and use Ada in a C++ project
---
import { Steps } from '@astrojs/starlight/components';

More information about the API can be found from [C++ API Reference](https://cpp-api.ada-url.com).

## Requirements

The project is self-contained and has no dependency.
A recent C++ compiler supporting C++17. We test GCC 9 or better, LLVM 10 or better and Microsoft Visual Studio 2022.

## Building

Ada uses **cmake** as a build system. It's recommended to have cmake available in your system.
Run the following commands to compile and build Ada locally.

<Steps>

1. **Prepare**

```bash
cmake -B build
```

2. **Build**

```bash
cmake --build build
```

</Steps>

## Usage

Use the following code to run and test Ada.

```cpp
#include "ada.h"
#include <iostream>

int main(int , char *[]) {
ada::result<ada::url_aggregator> url = ada::parse<ada::url_aggregator>("https://www.google.com");
url->set_protocol("http");
std::cout << url->get_protocol() << std::endl;
std::cout << url->get_host() << std::endl;
return EXIT_SUCCESS;
}
```

### Parsing & Validation

Parse and validate a URL from an ASCII or UTF-8 string

```cpp
ada::result<ada::url_aggregator> url =
ada::parse<ada::url_aggregator>("https://www.google.com");
if (url) { /* URL is valid */ }
```

After calling **parse** function, you *must* check that the result is valid before
accessing it when you are not sure that it will succeed. The following
code is unsafe:

```cpp
ada::result<ada::url_aggregator> url =
ada::parse<ada::url_aggregator>("some bad url");
url->get_href();
```

You should do...

```cpp
ada::result<ada::url_aggregator> url =
ada::parse<ada::url_aggregator>("some bad url");
if(url) {
// next line is now safe:
url->get_href();
} else {
// report a parsing failure
}
```

For simplicity, in the examples below, we skip the check because
we know that parsing succeeds.

## Examples

### Credentials

```cpp
auto url = ada::parse<ada::url_aggregator>("https://www.google.com");
url->set_username("username");
url->set_password("password");
// ada->get_href() will return "https://username:[email protected]/"
```

### Protocol

```cpp
auto url = ada::parse<ada::url_aggregator>("https://www.google.com");
url->set_protocol("wss");
// url->get_protocol() will return "wss:"
// url->get_href() will return "wss://www.google.com/"
```

### Host

```cpp
auto url = ada::parse<ada::url_aggregator>("https://www.google.com");
url->set_host("github.com");
// url->get_host() will return "github.com"
// you can use `url.set_hostname` depending on your usage.
```

### Port

```cpp
auto url = ada::parse<ada::url_aggregator>("https://www.google.com");
url->set_port("8080");
// url->get_port() will return "8080"
```

### Pathname

```cpp
auto url = ada::parse<ada::url_aggregator>("https://www.google.com");
url->set_pathname("/my-super-long-path")
// url->get_pathname() will return "/my-super-long-path"
```

### Search/Query

```cpp
auto url = ada::parse<ada::url_aggregator>("https://www.google.com");
url->set_search("target=self");
// url->get_search() will return "?target=self"
```

### Hash/Fragment

```cpp
auto url = ada::parse<ada::url_aggregator>("https://www.google.com");
url->set_hash("is-this-the-real-life");
// url->get_hash() will return "#is-this-the-real-life"
```
6 changes: 6 additions & 0 deletions astro/content/docs/clients/go.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
title: Go
description: How to install and use Ada in a Go project
---

Ada has a Go client available on [Github](https://github.com/ada-url/goada).
65 changes: 65 additions & 0 deletions astro/content/docs/clients/luajit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
---
title: LuaJIT
description: How to install and use Ada in a LuaJIT or OpenResty project
---

Ada has a LuaJIT / OpenResty client available on [Github][source-code],
and also on [luarocks.org][rock] and [https://opm.openresty.org/][opm].

## Installation

### Using LuaRocks

```bash
luarocks install lua-resty-ada
```

LuaRocks repository for `lua-resty-ada` is located at
[luarocks.org/modules/bungle/lua-resty-ada](https://luarocks.org/modules/bungle/lua-resty-session).

### Using OpenResty Package Manager

```bash
opm get bungle/lua-resty-ada
```

OPM repository for `lua-resty-ada` is located at
[opm.openresty.org/package/bungle/lua-resty-ada](https://opm.openresty.org/package/bungle/lua-resty-ada/).

## Usage

Please consult the [API documentation][documentation] for a more detailed information.

### URL class

The `resty.ada` can parse URL and return an instance of URL:

```lua
local ada_url = require("resty.ada")
local url = ada_url.parse("https://example.org/path/file.txt")
local protocol = url:get_protocol()
url:free() -- explicit free (garbage collector would do it implicitly)
print(protocol) -- "https:"
```

### Static functions

The library can also be used without creating instances:

```lua
local ada_url = require("resty.ada")
local protocol = ada_url.get_protocol("https://example.org/path/file.txt")
print(protocol) -- "https:"
```

## Resources

- [Source code][source-code]
- [LuaRocks][rock]
- [OpenResty Package Manager][opm]
- [Documentation][documentation]

[rock]: https://luarocks.org/modules/bungle/lua-resty-ada
[opm]: https://opm.openresty.org/package/bungle/lua-resty-ada/
[documentation]: https://bungle.github.io/lua-resty-ada/
[source-code]: https://github.com/bungle/lua-resty-ada
89 changes: 89 additions & 0 deletions astro/content/docs/clients/python.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
---
title: Python
description: How to install and use Ada in a Python project
---
import { Steps } from '@astrojs/starlight/components';

Ada has a Python client available on [Github](https://github.com/ada-url/ada-python).
For more details on the `ada_url` API, see the documentation at [Read the Docs](https://ada-url.readthedocs.io/en/latest/).

## Installation

### Installing pre-built binary wheels

The easiest way to get started is to install `ada-url` from [PyPI](https://pypi.org/project/ada-url/).

From within your virtual environment, run:

```bash
python3 -m pip install ada-url
```

### Installing from source

The `Makefile` in the [project root](https://github.com/ada-url/ada-python) will build a package for installation on your own machine.

From within your virtual environment, run:

<Steps>

1. **Prepare**

```bash
make requirements package
```

2. **Install**

```bash
python3 -m install -e .
```

</Steps>

## Usage

### URL class

The `ada_url` package defines a `URL` class that can parse URLs:

```py
>>> import ada_url
>>> urlobj = ada_url.URL('https://example.org/path/file.txt')
>>> urlobj.protocol
'https:'
>>> urlobj.pathname
'/path/file.txt'
```

### High-level functions

It also exposes some higher level functions for analyzing and manipulating URLs:

#### parse_url

```py
>>> import ada_url
>>> ada_url.parse_url('https://user:[email protected]:80/api?q=1#2')
{
'href': 'https://user:[email protected]:80/api?q=1#2',
'username': 'user',
'password': 'pass',
'protocol': 'https:',
'host': 'example.org:80',
'port': '80',
'hostname': 'example.org',
'pathname': '/api',
'search': '?q=1',
'hash': '#2'
}
```

#### join_url

```py
>>> import ada_url
>>> ada_url.join_url(
'https://example.org/dir/child.txt', '../parent.txt'
)
```
Loading