|
|
# 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...
|
|
|
|
|
|

|
|
|
|
|
|
## 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 |