Skip to content
GitLab
  • Menu
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • F FastAPI
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 0
    • Issues 0
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Deployments
    • Deployments
    • Releases
  • Packages & Registries
    • Packages & Registries
    • Package Registry
    • Container Registry
    • Infrastructure Registry
  • Wiki
    • Wiki
  • Activity
  • Graph
  • Create a new issue
  • Commits
  • Issue Boards
Collapse sidebar
  • Sitemule
  • Public
  • workshops
  • open source on IBM i
  • FastAPI
  • Wiki
  • Part 1b. Testing my first service

Part 1b. Testing my first service · Changes

Page history
Update Part 1b. Testing my first service authored Oct 29, 2021 by Jens Melgard Churchill's avatar Jens Melgard Churchill
Hide whitespace changes
Inline Side-by-side
Part-1b.-Testing-my-first-service.md
View page @ f1908a52
......@@ -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
Clone repository
  • Part 1a. My first service
  • Part 1b. Testing my first service
  • Part 2a. Extending my first service
  • Part 2b. Organise my first service
  • Part 3a. Review my first service
  • Part 3b. Connecting my first service
  • Home