Skip to content

Commit 3edbe09

Browse files
Ethan-Arrowoodcb1kenobikriszyp
authored
Create "Harper Applications in Depth" Learn Guide (#426)
* start on draft of new guide section * oops, include changes to prev guide too * wip * wip * expand operations section, more resource focus * its coming together!! * remove ai links so we can preview * rename and simplify intro section * finish learn guide drafts * forgot about basic-auth component * fix up new learn guide * format * delete coming soon page * fix capitalization, add more reference links to text, and other small updates * Apply suggestions from code review Co-authored-by: Chris Barber <chris@harperdb.io> * Update learn/developers/harper-applications-in-depth.mdx Co-authored-by: Kris Zyp <kriszyp@gmail.com> * review fixes * fix auth component due to prettier bug * tweak restart --------- Co-authored-by: Chris Barber <chris@harperdb.io> Co-authored-by: Kris Zyp <kriszyp@gmail.com>
1 parent 58b4fb6 commit 3edbe09

File tree

6 files changed

+748
-23
lines changed

6 files changed

+748
-23
lines changed

learn/developers/coming-soon.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

learn/developers/harper-applications-in-depth.mdx

Lines changed: 631 additions & 0 deletions
Large diffs are not rendered by default.

learn/getting-started/create-your-first-application.mdx

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ title: Create Your First Application
55
import Tabs from '@theme/Tabs';
66
import TabItem from '@theme/TabItem';
77

8+
import HarperArchitectureDiagram from '../../src/components/learn/harper-architecture-diagram.mdx';
9+
import BasicAuthentication from '../../src/components/learn/basic-authentication.mdx';
10+
811
With Harper successfully installed and setup, let's dive into building your first Harper Application, a simple REST API. Harper lets you build powerful APIs with minimal effort.
912

1013
## What You Will Learn
@@ -24,22 +27,7 @@ With Harper successfully installed and setup, let's dive into building your firs
2427

2528
Before diving into building your first Harper application, it is important to understand a bit about Harper's architecture. The simplest way to think about Harper is as a stack.
2629

27-
```
28-
┏━━━━━━━━━━━━━━━━━━┓
29-
┃ Applications ┃
30-
┠──────────────────┨
31-
┃ Plugins ┃
32-
┃ - rest ┃
33-
┃ - graphqlSchema ┃
34-
┃ - ... ┃
35-
┠──────────────────┨
36-
┃ Core Services: ┃
37-
┃ - database ┃
38-
┃ - networking ┃
39-
┃ - component ┃
40-
┃ management ┃
41-
┗━━━━━━━━━━━━━━━━━━┛
42-
```
30+
<HarperArchitectureDiagram />
4331

4432
At the bottom are the **core services** that make up the foundation of the Harper platform. This includes the high-performance **database**, extensible **networking** middleware, and **component** management system. Components are extensions of the core Harper system, and are further classified as **plugins** and **applications**.
4533

@@ -220,13 +208,28 @@ If you need to check your work, checkout the [`02-rest-api`](https://github.com/
220208

221209
With everything in place, now its time to create your first record for the `Dog` table.
222210

223-
With the automatic REST API generation you have a plethora of options for interacting with the `Dog` table. We'll keep it simple for now, but will explore everything this has to offer in later guides.
211+
The goal is to create a new `Dog` record with an ID of `001` and the properties:
224212

225-
Create a `PUT` request using the REST API port and the path `/Dog/001`. Include a JSON body with the specified attributes except for `id`. The `001` in the URL will be used as the ID for this entry.
213+
```json
214+
{
215+
"name": "Harper",
216+
"breed": "Black Labrador / Chow Mix",
217+
"age": 5
218+
}
219+
```
226220

227-
:::note
228-
If you're using Fabric remember to replace the `localhost` with your cluster's URL
229-
:::
221+
With the automatic REST API generation you enabled in the previous step, you now have a plethora of options for interacting with the `Dog` table.
222+
223+
Fabric users should use the UI directly, but can optionally follow along with the following request snippets if they want. Importantly, Fabric users must do things differently:
224+
225+
1. Replace `http://localhost` with their Fabric instance's URL
226+
2. Include an Authorization header in the requests.
227+
228+
Here is some additional information on how to create a Basic Authentication token:
229+
230+
<BasicAuthentication />
231+
232+
Create a `PUT` request using the REST API port and the path `/Dog/001`. Include a JSON body with the specified attributes except for `id`. The `001` in the URL will be used as the ID for this entry.
230233

231234
<Tabs groupId="http-client">
232235
<TabItem value="curl">
@@ -264,7 +267,7 @@ console.log(response.status);
264267
</TabItem>
265268
</Tabs>
266269

267-
If you see `204` status code, then the record was successfully created!
270+
If you see a `204` status code, then the record was successfully created!
268271

269272
## Read a Record
270273

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{/* Due to a bug in prettier formatting (https://github.com/prettier/prettier/issues/17700) we can't retain multi-line comments with empty lines. */}
2+
{/* So instead, just store this edition of this component in a separate file until we get to update. */}
3+
{/* Replace `basic-authentication.mdx` with this when we switch from using `atob()` here https://github.com/HarperFast/harper/blob/main/security/auth.ts#L181 potentially in v5 */}
4+
5+
<details>
6+
<summary>Basic Authentication</summary>
7+
8+
The simplest authorization scheme is [Basic Authentication](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/Authentication#basic_authentication_scheme) which transmits credentials as username/password pairs encoded using base64. Importantly, this scheme does not encrypt credentials. If used over an insecure connection, such as HTTP, they are susceptible to being compromised. Only ever use Basic Authentication over secured connections, such as HTTPS. Even then, its better to upgrade to an encryption based authentication scheme or certificates. Harper supports many different authentication mechanisms, and they will all be covered in later Learn guides.
9+
10+
Use the username and password values from the previous [Install and Connect](/learn/getting-started/install-and-connect-harper) guide to generate an authorization value. The important part is to combine the `username` and `password` using a colon `:` character, encode that using base64, and then append the result to `"Basic "`.
11+
12+
Here are some efficient methodologies:
13+
14+
{/* Maybe consider using Tabs here with labels like "Node.js <=v24" and ("Web" or "Winter" or "W/MCA" if defined that abbreviation earlier somehow?) */}
15+
16+
In Node.js v24 or earlier use the [`Buffer`](https://nodejs.org/docs/latest/api/buffer.html) API:
17+
18+
```typescript
19+
// Ensure you replace these with your installation's values
20+
const username = 'HDB_ADMIN';
21+
const password = 'abc123!';
22+
const credentials = Buffer.from(`${username}:${password}`).toString('base64');
23+
const authorizationValue = `Basic ${credentials}`;
24+
```
25+
26+
For Node.js v25 or later, most web browser consoles, and any WinterTC Minimum Common API compatible runtime use the [`Uint8Array.prototype.toBase64()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/toBase64) API:
27+
28+
```typescript
29+
// Ensure you replace these with your installation's values
30+
const username = 'HDB_ADMIN';
31+
const password = 'abc123!';
32+
const credentials = new TextEncoder().encode(`${username}:${password}`).toBase64();
33+
const authorizationValue = `Basic ${credentials}`;
34+
```
35+
36+
> Both of these options are preferred over [`btoa()`](https://developer.mozilla.org/en-US/docs/Web/API/Window/btoa) do to its limitation to Latin-1 character set.
37+
38+
You would use the `authorizationValue` as the value for the `Authorization` header such as:
39+
40+
```typescript
41+
fetch('/', {
42+
// ...
43+
headers: {
44+
Authorization: authorizationValue,
45+
},
46+
// ...
47+
});
48+
```
49+
50+
</details>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<details>
2+
<summary>Basic Authentication</summary>
3+
4+
The simplest authorization scheme is [Basic Authentication](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/Authentication#basic_authentication_scheme) which transmits credentials as username/password pairs encoded using base64. Importantly, this scheme does not encrypt credentials. If used over an insecure connection, such as HTTP, they are susceptible to being compromised. Only ever use Basic Authentication over secured connections, such as HTTPS. Even then, its better to upgrade to an encryption based authentication scheme or certificates. Harper supports many different authentication mechanisms, and they will all be covered in later Learn guides.
5+
6+
Use the username and password values from the previous [Install and Connect](/learn/getting-started/install-and-connect-harper) guide to generate an authorization value. The important part is to combine the `username` and `password` using a colon `:` character, encode that using base64, and then append the result to `"Basic "`.
7+
8+
```typescript
9+
const username = 'HDB_ADMIN';
10+
const password = 'abc123!';
11+
const authorizationValue = `Basic ${btoa(`${username}:${password}`)}`;
12+
```
13+
14+
You would use the `authorizationValue` as the value for the `Authorization` header such as:
15+
16+
```typescript
17+
fetch('/', {
18+
// ...
19+
headers: {
20+
Authorization: authorizationValue,
21+
},
22+
// ...
23+
});
24+
```
25+
26+
</details>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
```
2+
┏━━━━━━━━━━━━━━━━━━┓
3+
┃ Applications ┃
4+
┠──────────────────┨
5+
┃ Plugins ┃
6+
┃ - rest ┃
7+
┃ - graphqlSchema ┃
8+
┃ - ... ┃
9+
┠──────────────────┨
10+
┃ Core Services: ┃
11+
┃ - database ┃
12+
┃ - networking ┃
13+
┃ - component ┃
14+
┃ management ┃
15+
┗━━━━━━━━━━━━━━━━━━┛
16+
```

0 commit comments

Comments
 (0)