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 0 → 100644
View page @ 805837dd
# Using curl to test your first FastAPI service on IBM i.
Now that we've coded a service, we want to start it and test it
## Starting a FastAPI service, and making it a background task
In the shell, type `python -m hypercorn main:app --bind ":${HTTP_PORT:-9000}"`
_The environment variable_ `HTTP_PORT` _is defined pr. user on our test server, ensuring we don't collide with each other.\
The_ `:-9000` _is a fallback, in case that variable isn't set in your environment._
Now that the service is running, we want to test it.
First send it to the background by pressing `Ctrl+z`, this "pauses" the service,
Now type `bg` the service will be resumed, but is now running in the background.
Following the last few pages, you should be looking at this...
![image](uploads/7f7b8371186313f9e6e54246834c2ba0/image.png)
## Actually testing the thing
Now to test the service, we'll use the `curl` command, in combination with the `jq` command , type:
`curl -sS localhost:${HTTP_PORT:-9000} | jq .`
If everything has gone right, we''ll get a response from the service in JSON format, which `jq` will pretty print.
```plaintext
{
"Hello": "World"
}
```
Now we're cooking, 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