... | ... | @@ -33,7 +33,62 @@ If everything has gone right, we''ll get a response from the service in JSON for |
|
|
}
|
|
|
```
|
|
|
|
|
|
Now we're cooking, time to actually build something!
|
|
|
Awesome, we have life! - Let's test some more, remember the other endpoint?...
|
|
|
|
|
|
`curl -sS localhost:${HTTP_PORT:-9000}/items | jq .`
|
|
|
|
|
|
```
|
|
|
{
|
|
|
"detail": "Not Found"
|
|
|
}
|
|
|
```
|
|
|
|
|
|
Not found... Curious?\
|
|
|
The reason is simple, remember the endpoint `/items` requires a **none-optional** _path-variable_ `item_id`\
|
|
|
FastAPI will enforce that! - let's try again...
|
|
|
|
|
|
`curl -sS localhost:${HTTP_PORT:-9000}/items/id-1 | jq .`
|
|
|
|
|
|
```
|
|
|
{
|
|
|
"detail": [
|
|
|
{
|
|
|
"loc": [
|
|
|
"path",
|
|
|
"item_id"
|
|
|
],
|
|
|
"msg": "value is not a valid integer",
|
|
|
"type": "type_error.integer"
|
|
|
}
|
|
|
]
|
|
|
}
|
|
|
```
|
|
|
|
|
|
This one you might have guessed already, remember we defined item_id as `item_id :int` in the function\
|
|
|
You can rest assured, FastAPI we'll type check that - less type checking in our business logic, nice!
|
|
|
|
|
|
Let's get a proper result, this time adding the **optional** query-string argument `q` as well
|
|
|
|
|
|
`curl -sS localhost:${HTTP_PORT:-9000}/items/1?q=abc | jq .`
|
|
|
|
|
|
```
|
|
|
{
|
|
|
"item_id": 1,
|
|
|
"q": "abc"
|
|
|
}
|
|
|
```
|
|
|
|
|
|
Cool, but aren't we leaving
|
|
|
|
|
|
Knowing that we can test from the shell is nice, and very useful for automation, but lets head over to the browser shall we?
|
|
|
|
|
|
Open [https://your.ibmi.rocks/](https://your.ibmi.rocks/{your-workshop-id}/) and enter your user id, the resulting URI is the one we'll work with from here on out.
|
|
|
|
|
|
Lets end the service by bringing it to the foreground, and stopping it.
|
|
|
|
|
|
To bring the process back to the foreground run `fg`\
|
|
|
Now simply cancel it by pressing `Ctrl+c`
|
|
|
|
|
|
Good stuff, time to actually build something!
|
|
|
|
|
|
[Graduate to part 2...](Part-2a.-Extending-my-first-service) |
|
|
\ No newline at end of file |