1
0
mirror of https://github.com/actix/examples synced 2025-06-26 17:17:42 +02:00

format markdown

This commit is contained in:
Rob Ede
2022-03-06 00:43:10 +00:00
parent f27cc4b6b4
commit e239414a55
31 changed files with 165 additions and 188 deletions

View File

@ -1,10 +1,6 @@
# JSON decode errors
This example demonstrates how to return useful error messages to the client
when the server receives a request with invalid JSON, or which cannot be
deserialized to the expected model. By configuring an `error_handler` on the
route, we can set appropriate response codes and return the string
representation of the error.
This example demonstrates how to return useful error messages to the client when the server receives a request with invalid JSON, or which cannot be deserialized to the expected model. By configuring an `error_handler` on the route, we can set appropriate response codes and return the string representation of the error.
## Usage
@ -16,9 +12,7 @@ cargo run
## Examples
The examples use `curl -i` in order to show the status line with the response
code. The response headers have been omitted for brevity, and replaced with an
ellipsis `...`.
The examples use `curl -i` in order to show the status line with the response code. The response headers have been omitted for brevity, and replaced with an ellipsis `...`.
- A well-formed request
@ -27,7 +21,7 @@ ellipsis `...`.
HTTP/1.1 200 OK
...
Hello Alice!
Hello Alice!
```
- Missing `Content-Type` header

View File

@ -1,10 +1,6 @@
This is a contrived example intended to illustrate a few important Actix Web features.
*Imagine* that you have a process that involves 3 steps. The steps here
are dumb in that they do nothing other than call an HTTP endpoint that
returns the json that was posted to it. The intent here is to illustrate
how to chain these steps together as futures and return a final result
in a response.
_Imagine_ that you have a process that involves 3 steps. The steps here are dumb in that they do nothing other than call an HTTP endpoint that returns the json that was posted to it. The intent here is to illustrate how to chain these steps together as futures and return a final result in a response.
Actix Web features illustrated here include:
@ -14,7 +10,6 @@ Actix Web features illustrated here include:
- POSTing json body
3. chaining futures into a single response used by an asynch endpoint
### server
```sh
@ -23,5 +18,4 @@ cargo run
# Started http server: 127.0.0.1:8080
```
Example query from the command line using httpie:
```echo '{"id":"1", "name": "JohnDoe"}' | http 127.0.0.1:8080/something```
Example query from the command line using httpie: `echo '{"id":"1", "name": "JohnDoe"}' | http 127.0.0.1:8080/something`

View File

@ -18,31 +18,31 @@ With [Postman](https://www.getpostman.com/) or [Rested](moz-extension://60daeb1c
- POST / (embed serde-json):
- method : ``POST``
- url : ``http://127.0.0.1:8080/``
- header : ``Content-Type`` = ``application/json``
- body (raw) : ``{"name": "Test user", "number": 100}``
- method : `POST`
- url : `http://127.0.0.1:8080/`
- header : `Content-Type` = `application/json`
- body (raw) : `{"name": "Test user", "number": 100}`
- POST /manual (manual serde-json):
- method : ``POST``
- url : ``http://127.0.0.1:8080/manual``
- header : ``Content-Type`` = ``application/json``
- body (raw) : ``{"name": "Test user", "number": 100}``
- method : `POST`
- url : `http://127.0.0.1:8080/manual`
- header : `Content-Type` = `application/json`
- body (raw) : `{"name": "Test user", "number": 100}`
- POST /mjsonrust (manual json-rust):
- method : ``POST``
- url : ``http://127.0.0.1:8080/mjsonrust``
- header : ``Content-Type`` = ``application/json``
- body (raw) : ``{"name": "Test user", "number": 100}`` (you can also test ``{notjson}``)
- method : `POST`
- url : `http://127.0.0.1:8080/mjsonrust`
- header : `Content-Type` = `application/json`
- body (raw) : `{"name": "Test user", "number": 100}` (you can also test `{notjson}`)
### python client
- ``pip install aiohttp``
- ``python client.py``
- `pip install aiohttp`
- `python client.py`
if ubuntu :
- ``pip3 install aiohttp``
- ``python3 client.py``
- `pip3 install aiohttp`
- `python3 client.py`

View File

@ -17,7 +17,6 @@ $ curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc": "2.0", "metho
# {"jsonrpc":"2.0","result":"pong","error":null,"id":1}
```
**python**
```sh