Skip to content

Commit

Permalink
Adding some clarifying instructions to the getting started page (#816)
Browse files Browse the repository at this point in the history
* add new sections for a little more explanation

* add space under infobox to have proper backtick display

* change '127.0.0.1' to 'localhost'

---------

Co-authored-by: Elad Kaplan <[email protected]>
  • Loading branch information
isaacdonaldson and kaplanelad authored Oct 13, 2024
1 parent 514f412 commit 9a83331
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions docs-site/content/docs/getting-started/tour/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ If you select all defaults, you'll have:


Now `cd` into your `myapp` and start your app by running `cargo loco start`:


<div class="infobox">

If you have the `Client` asset serving option configured, make sure you build your frontend before starting the server. This can be done by changing into the frontend directory (`cd frontend`) and running `pnpm install` and `pnpm build`.
</div>

<!-- <snip id="starting-the-server-command-with-output" inject_from="yaml" template="sh"> -->
```sh
Expand Down Expand Up @@ -76,6 +82,7 @@ listening on port 5150


<div class="infobox">

You don't have to run things through `cargo` but in development it's highly
recommended. If you build `--release`, your binary contains everything
including your code and `cargo` or Rust is not needed. </div>
Expand All @@ -84,6 +91,11 @@ listening on port 5150

We have a base SaaS app with user authentication generated for us. Let's make it a blog backend by adding a `post` and a full CRUD API using `scaffold`:

<div class="infobox">

You can choose between generating an `api`, `html` or `htmx` scaffold using the required `-k` flag.
</div>

```sh
$ cargo loco generate scaffold post title:string content:text -k api

Expand Down Expand Up @@ -127,6 +139,14 @@ listening on port 5150
```
<!-- </snip> -->

<div class="infobox">

Depending on which `-k` option you chose, the steps for creating a scaffolded resource will change. With the `api` flag or the `htmx` flag you can use the below example. But with the `html` flag, it is recommended you do the post creation steps in your browser.

If you want to use `curl` to test the `html` scaffold, you will need to send your requests with the Content-Type `application/x-www-form-urlencoded` and the body as `title=Your+Title&content=Your+Content` by default. This can be changed to allow `application/json` as a `Content-Type` in the code if desired.

</div>

Next, try adding a `post` with `curl`:

```sh
Expand Down Expand Up @@ -160,7 +180,7 @@ Your generated app contains a fully working authentication suite, based on JWTs.
The `/api/auth/register` endpoint creates a new user in the database with an `email_verification_token` for account verification. A welcome email is sent to the user with a verification link.

```sh
$ curl --location '127.0.0.1:5150/api/auth/register' \
$ curl --location 'localhost:5150/api/auth/register' \
--header 'Content-Type: application/json' \
--data-raw '{
"name": "Loco user",
Expand All @@ -176,7 +196,7 @@ For security reasons, if the user is already registered, no new user is created,
After registering a new user, use the following request to log in:

```sh
$ curl --location '127.0.0.1:5150/api/auth/login' \
$ curl --location 'localhost:5150/api/auth/login' \
--header 'Content-Type: application/json' \
--data-raw '{
"email": "[email protected]",
Expand All @@ -203,7 +223,7 @@ In your client-side app, you save this JWT token and make following requests wit
This endpoint is protected by auth middleware. We will use the token we got earlier to perform a request with the _bearer token_ technique (replace `TOKEN` with the JWT token you got earlier):

```sh
$ curl --location --request GET '127.0.0.1:5150/api/user/current' \
$ curl --location --request GET 'localhost:5150/api/user/current' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer TOKEN'
```
Expand Down

0 comments on commit 9a83331

Please sign in to comment.