diff --git a/README.md b/README.md index 40c2320..31aa909 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,7 @@ - [Mozilla Services Skeleton App](https://github.com/mozilla-services/skeleton) ## Paid Resources + - [book] [Zero2prod by Luca Palmieri](https://algoluca.gumroad.com/l/zero2prod): Takes you on a journey to discover the world of backend development in Rust. ## Contribute diff --git a/auth/cookie-auth/README.md b/auth/cookie-auth/README.md index 2ba3245..7ae3e35 100644 --- a/auth/cookie-auth/README.md +++ b/auth/cookie-auth/README.md @@ -26,7 +26,7 @@ Now with the cookie `auth-example` sent in a GET request, the `user1` is recogni > GET / HTTP/1.1 > Host: localhost:8080 > Cookie: auth-example=GRm2Vku0UpFbJ3CNTKbndzIYHVGi8wc8eoXm/Axtf2BO - > + > < HTTP/1.1 200 OK - < + < Hello user1 diff --git a/auth/simple-auth-server/README.md b/auth/simple-auth-server/README.md index 73c2eaf..1fe4284 100644 --- a/auth/simple-auth-server/README.md +++ b/auth/simple-auth-server/README.md @@ -33,7 +33,6 @@ - [sparkpost](https://crates.io/crates/sparkpost) // Rust bindings for sparkpost email api v1. - [uuid](https://crates.io/crates/uuid) // A library to generate and parse UUIDs. - Read the full tutorial series on [gill.net.in](https://gill.net.in) - [Auth Web Microservice with Rust using Actix Web v2 - Complete Tutorial](https://gill.net.in/posts/auth-microservice-rust-actix-web1.0-diesel-complete-tutorial/) diff --git a/basics/static-files/README.md b/basics/static-files/README.md index 874f54c..1d8d241 100644 --- a/basics/static-files/README.md +++ b/basics/static-files/README.md @@ -2,9 +2,8 @@ Demonstrates how to serve static files. Inside the `./static` folder you will find 2 subfolders: -* `root`: A tree of files that will be served at the web root `/`. This includes the `css` and `js` folders, each - containing an example file. -* `images`: A list of images that will be served at `/images` path, with file listing enabled. +- `root`: A tree of files that will be served at the web root `/`. This includes the `css` and `js` folders, each containing an example file. +- `images`: A list of images that will be served at `/images` path, with file listing enabled. ## Usage diff --git a/cors/README.md b/cors/README.md index 07b5017..b50c02f 100644 --- a/cors/README.md +++ b/cors/README.md @@ -1,16 +1,20 @@ -# Actix Web CORS example +# Cross-Origin Resource Sharing (CORS) ## Run Server + ```sh cd cors/backend cargo run ``` ## Run Frontend + In a separate terminal, also run: + ```sh cd cors/frontend npm install npm run serve ``` + then open browser at: http://localhost:8080 diff --git a/data-factory/README.md b/data-factory/README.md index 7ead31d..e956c37 100644 --- a/data-factory/README.md +++ b/data-factory/README.md @@ -1,23 +1,27 @@ # Usage: + This is an example demonstrating the construction of async state with `App::data_factory` ## Reason: + Use of a `data_factory` would make sense in these situations: + - When async state does not necessarily have to be shared between workers/threads. -- When an async state would spawn tasks on `actix-rt`. If state was centralized there could be a possibility the tasks get an unbalanced distribution on the workers/threads -(`actix-rt` would spawn tasks on local thread whenever it's called) +- When an async state would spawn tasks on `actix-rt`. If state was centralized there could be a possibility the tasks get an unbalanced distribution on the workers/threads (`actix-rt` would spawn tasks on local thread whenever it's called) ## Requirement: + - `rustc 1.58 stable` - `redis` server listen on `127.0.0.1:6379`(or use `REDIS_URL` env argument when starting the example) ## Endpoints: + - use a work load generator(e.g wrk) to benchmark the end points: http://127.0.0.1:8080/pool prebuilt shared redis pool http://127.0.0.1:8080/pool2 data_factory redis pool ## Context: -The real world difference can be vary by the work you are doing but in general it's a good idea to -spread your *identical* async tasks evenly between threads and have as little cross threads synchronization as possible. + +The real world difference can be vary by the work you are doing but in general it's a good idea to spread your _identical_ async tasks evenly between threads and have as little cross threads synchronization as possible. diff --git a/databases/diesel/README.md b/databases/diesel/README.md index e56f937..90fb3ae 100644 --- a/databases/diesel/README.md +++ b/databases/diesel/README.md @@ -48,30 +48,35 @@ cargo run Inserts a new user into the SQLite DB. Provide a JSON payload with a name. Eg: + ```json { "name": "bill" } ``` On success, a response like the following is returned: + ```json { - "id": "9e46baba-a001-4bb3-b4cf-4b3e5bab5e97", - "name": "bill" + "id": "9e46baba-a001-4bb3-b4cf-4b3e5bab5e97", + "name": "bill" } ```
Client Examples - Using [HTTPie](https://httpie.org/): - ```sh - http POST localhost:8080/user name=bill - ``` +Using [HTTPie](https://httpie.org/): + +```sh +http POST localhost:8080/user name=bill +``` + +Using cURL: + +```sh +curl -S -X POST --header "Content-Type: application/json" --data '{"name":"bill"}' http://localhost:8080/user +``` - Using cURL: - ```sh - curl -S -X POST --header "Content-Type: application/json" --data '{"name":"bill"}' http://localhost:8080/user - ```
#### `GET /user/{user_uid}` @@ -81,15 +86,18 @@ Gets a user from the DB using its UID (returned from the insert request or taken
Client Examples - Using [HTTPie](https://httpie.org/): - ```sh - http localhost:8080/user/9e46baba-a001-4bb3-b4cf-4b3e5bab5e97 - ``` +Using [HTTPie](https://httpie.org/): + +```sh +http localhost:8080/user/9e46baba-a001-4bb3-b4cf-4b3e5bab5e97 +``` + +Using cURL: + +```sh +curl -S http://localhost:8080/user/9e46baba-a001-4bb3-b4cf-4b3e5bab5e97 +``` - Using cURL: - ```sh - curl -S http://localhost:8080/user/9e46baba-a001-4bb3-b4cf-4b3e5bab5e97 - ```
### Explore The SQLite DB @@ -103,7 +111,6 @@ sqlite> .tables sqlite> SELECT * FROM users; ``` - ## Using Other Databases You can find a complete example of Diesel + PostgreSQL at: [https://github.com/TechEmpower/FrameworkBenchmarks/tree/master/frameworks/Rust/actix](https://github.com/TechEmpower/FrameworkBenchmarks/tree/master/frameworks/Rust/actix) diff --git a/databases/mongodb/README.md b/databases/mongodb/README.md index bf5452e..c457818 100644 --- a/databases/mongodb/README.md +++ b/databases/mongodb/README.md @@ -1,23 +1,16 @@ # MongoDB -Simple example of MongoDB usage with Actix Web. For more information on the MongoDB Rust driver, -visit the [documentation](https://docs.rs/mongodb/2.0.0/mongodb/index.html) and -[source code](https://github.com/mongodb/mongo-rust-driver). +Simple example of MongoDB usage with Actix Web. For more information on the MongoDB Rust driver, visit the [documentation](https://docs.rs/mongodb/2.0.0/mongodb/index.html) and [source code](https://github.com/mongodb/mongo-rust-driver). ## Usage ### Install MongoDB -Visit the [MongoDB Download Center](https://www.mongodb.com/try) for instructions on how to use -MongoDB Atlas or set up MongoDB locally. +Visit the [MongoDB Download Center](https://www.mongodb.com/try) for instructions on how to use MongoDB Atlas or set up MongoDB locally. ### Set an environment variable -The example code creates a client with the URI set by the `MONGODB_URI` environment variable. The -default URI for a standalone `mongod` running on localhost is "mongodb://localhost:27017". For more -information on MongoDB URIs, visit the -[connection string](https://docs.mongodb.com/manual/reference/connection-string/) entry in the -MongoDB manual. +The example code creates a client with the URI set by the `MONGODB_URI` environment variable. The default URI for a standalone `mongod` running on localhost is "mongodb://localhost:27017". For more information on MongoDB URIs, visit the [connection string](https://docs.mongodb.com/manual/reference/connection-string/) entry in the MongoDB manual. ### Run the example diff --git a/databases/postgres/README.md b/databases/postgres/README.md index 77ce5e6..7cf088b 100644 --- a/databases/postgres/README.md +++ b/databases/postgres/README.md @@ -11,62 +11,56 @@ 1. Create database user - ```shell - createuser -P test_user - ``` + ```shell + createuser -P test_user + ``` - Enter a password of your choice. The following instructions assume you - used `testing` as password. + Enter a password of your choice. The following instructions assume you used `testing` as password. - This step is **optional** and you can also use an existing database user - for that. Just make sure to replace `test_user` by the database user - of your choice in the following steps and change the `.env` file - containing the configuration accordingly. + This step is **optional** and you can also use an existing database user for that. Just make sure to replace `test_user` by the database user of your choice in the following steps and change the `.env` file containing the configuration accordingly. 2. Create database - ```shell - createdb -O test_user testing_db - ``` + ```shell + createdb -O test_user testing_db + ``` 3. Initialize database - ```shell - psql -f sql/schema.sql testing_db - ``` + ```shell + psql -f sql/schema.sql testing_db + ``` - This step can be repeated and clears the database as it drops and - recreates the schema `testing` which is used within the database. + This step can be repeated and clears the database as it drops and recreates the schema `testing` which is used within the database. 4. Create `.env` file: - ```ini - SERVER_ADDR=127.0.0.1:8080 - PG.USER=test_user - PG.PASSWORD=testing - PG.HOST=127.0.0.1 - PG.PORT=5432 - PG.DBNAME=testing_db - PG.POOL.MAX_SIZE=16 - ``` + ```ini + SERVER_ADDR=127.0.0.1:8080 + PG.USER=test_user + PG.PASSWORD=testing + PG.HOST=127.0.0.1 + PG.PORT=5432 + PG.DBNAME=testing_db + PG.POOL.MAX_SIZE=16 + ``` 5. Run the server: - ```shell - cargo run - ``` + ```shell + cargo run + ``` 6. Using a different terminal send an HTTP POST request to the running server: - ```shell - echo '{"email": "ferris@thecrab.com", "first_name": "ferris", "last_name": "crab", "username": "ferreal"}' | http -f --json --print h POST http://127.0.0.1:8080/users - ``` + ```shell + echo '{"email": "ferris@thecrab.com", "first_name": "ferris", "last_name": "crab", "username": "ferreal"}' | http -f --json --print h POST http://127.0.0.1:8080/users + ``` - **...or using curl...** + **...or using curl...** - ```shell - curl -d '{"email": "ferris@thecrab.com", "first_name": "ferris", "last_name": "crab", "username": "ferreal"}' -H 'Content-Type: application/json' http://127.0.0.1:8080/users - ``` + ```shell + curl -d '{"email": "ferris@thecrab.com", "first_name": "ferris", "last_name": "crab", "username": "ferreal"}' -H 'Content-Type: application/json' http://127.0.0.1:8080/users + ``` - A unique constraint exists for username, so sending this request twice - will return an internal server error (HTTP 500). + A unique constraint exists for username, so sending this request twice will return an internal server error (HTTP 500). diff --git a/databases/redis/README.md b/databases/redis/README.md index adf768a..b8430cd 100644 --- a/databases/redis/README.md +++ b/databases/redis/README.md @@ -61,5 +61,5 @@ At any time, verify the contents of Redis using its CLI: echo "MGET mydomain:one mydomain:two mydomain:three" | redis-cli ``` -[HTTPie]: https://httpie.org -[cURL]: https://curl.haxx.se +[httpie]: https://httpie.org +[curl]: https://curl.haxx.se diff --git a/databases/sqlite/README.md b/databases/sqlite/README.md index 675b763..1422445 100644 --- a/databases/sqlite/README.md +++ b/databases/sqlite/README.md @@ -5,13 +5,13 @@ Getting started using databases with Actix Web, asynchronously. ### init database sqlite From the root directory of this project: + ```sh bash db/setup_db.sh ``` This creates a sqlite database, weather.db, in the root. - ### server ```sh @@ -26,7 +26,6 @@ cargo run [http://127.0.0.1:8080/parallel_weather](http://127.0.0.1:8080/parallel_weather) - ### sqlite client ```sh diff --git a/forms/multipart/README.md b/forms/multipart/README.md index edcd7d3..ef6d718 100644 --- a/forms/multipart/README.md +++ b/forms/multipart/README.md @@ -7,10 +7,10 @@ cd forms/multipart cargo run ``` -``` open web browser to localhost:8080 and upload file(s) ``` +`open web browser to localhost:8080 and upload file(s)` ### Result -``` file(s) will show up in ./tmp in the same directory as the running process ``` +`file(s) will show up in ./tmp in the same directory as the running process` Note: this is a naive implementation and will panic on any error diff --git a/graphql/juniper/README.md b/graphql/juniper/README.md index 9515e64..5856c5e 100644 --- a/graphql/juniper/README.md +++ b/graphql/juniper/README.md @@ -1,7 +1,6 @@ # GraphQL using Juniper -[Juniper](https://github.com/graphql-rust/juniper) integration for Actix Web. -If you want more advanced example, see also the [juniper-advanced example]. +[Juniper](https://github.com/graphql-rust/juniper) integration for Actix Web. If you want more advanced example, see also the [juniper-advanced example]. [juniper-advanced example]: https://github.com/actix/examples/tree/master/graphql/juniper-advanced @@ -37,9 +36,7 @@ _Result:_ "data": { "human": { "name": "Luke", - "appearsIn": [ - "NEW_HOPE" - ], + "appearsIn": ["NEW_HOPE"], "homePlanet": "Mars" } } @@ -50,7 +47,9 @@ _Mutation example:_ ```graphql mutation { - createHuman(newHuman: {name: "Fresh Kid Ice", appearsIn: EMPIRE, homePlanet: "earth"}) { + createHuman( + newHuman: { name: "Fresh Kid Ice", appearsIn: EMPIRE, homePlanet: "earth" } + ) { id name appearsIn @@ -67,9 +66,7 @@ _Result:_ "createHuman": { "id": "1234", "name": "Fresh Kid Ice", - "appearsIn": [ - "EMPIRE" - ], + "appearsIn": ["EMPIRE"], "homePlanet": "earth" } } diff --git a/guards/README.md b/guards/README.md index aa684da..d68e01e 100644 --- a/guards/README.md +++ b/guards/README.md @@ -1,6 +1,7 @@ # guards Shows how to set up custom routing guards. + - Routing different API versions using a header instead of path. ## Usage @@ -30,5 +31,5 @@ Using [cURL]: curl 'localhost:8080/api/hello' -H 'accept-version: 1' ``` -[HTTPie]: https://httpie.org -[cURL]: https://curl.haxx.se +[httpie]: https://httpie.org +[curl]: https://curl.haxx.se diff --git a/http-proxy/README.md b/http-proxy/README.md index 55bb9c7..e8d9986 100644 --- a/http-proxy/README.md +++ b/http-proxy/README.md @@ -1,11 +1,10 @@ ## HTTP naïve proxy example -This is a relatively simple HTTP proxy, forwarding HTTP requests to another HTTP server, including -request body, headers, and streaming uploads. +This is a relatively simple HTTP proxy, forwarding HTTP requests to another HTTP server, including request body, headers, and streaming uploads. To start: -``` shell +```shell cargo run -- # example: cargo run -- 127.0.0.1 3333 127.0.0.1 8080 diff --git a/https-tls/openssl/README.md b/https-tls/openssl/README.md index ab6eb8b..daa17c2 100644 --- a/https-tls/openssl/README.md +++ b/https-tls/openssl/README.md @@ -4,9 +4,7 @@ ### Certificate -We put the self-signed certificate in this directory as an example -but your browser would complain that it isn't secure. -So we recommend to use [`mkcert`] to trust it. To use local CA, you should run: +We put the self-signed certificate in this directory as an example but your browser would complain that it isn't secure. So we recommend to use [`mkcert`] to trust it. To use local CA, you should run: ```sh mkcert -install @@ -30,5 +28,5 @@ cargo run (or ``cargo watch -x run``) ### web client -- curl: ``curl -v https://127.0.0.1:8443/index.html --compressed -k`` +- curl: `curl -v https://127.0.0.1:8443/index.html --compressed -k` - browser: [https://127.0.0.1:8443/index.html](https://127.0.0.1:8443/index.html) diff --git a/https-tls/rustls-client-cert/README.md b/https-tls/rustls-client-cert/README.md index 6eb9b74..987d52a 100644 --- a/https-tls/rustls-client-cert/README.md +++ b/https-tls/rustls-client-cert/README.md @@ -4,8 +4,7 @@ ### Certificate -All the self-signed certificate are in the ./certs directory, including the CA certificate -generated by [`mkcert`] that was used to create the server and client certs. +All the self-signed certificate are in the ./certs directory, including the CA certificate generated by [`mkcert`] that was used to create the server and client certs. ### Server @@ -19,15 +18,17 @@ The server runs HTTP on port 8080 and HTTPS on port 8443. ### Providing Client Cert Using [HTTPie]: + ```sh http https://127.0.0.1:8443/ --verify=certs/rootCA.pem --cert=certs/client-cert.pem --cert-key=certs/client-key.pem ``` Using [cURL]: + ```sh curl https://127.0.0.1:8443/ --cacert certs/rootCA.pem --cert certs/client-cert.pem --key certs/client-key.pem ``` [`mkcert`]: https://github.com/FiloSottile/mkcert -[cURL]: https://curl.haxx.se/ -[HTTPie]: https://httpie.org/ +[curl]: https://curl.haxx.se/ +[httpie]: https://httpie.org/ diff --git a/https-tls/rustls/README.md b/https-tls/rustls/README.md index a9e1348..e6cbf9a 100644 --- a/https-tls/rustls/README.md +++ b/https-tls/rustls/README.md @@ -4,9 +4,7 @@ ### Certificate -We put the self-signed certificate in this directory as an example -but your browser would complain that it isn't secure. -So we recommend to use [`mkcert`] to trust it. To use local CA, you should run: +We put the self-signed certificate in this directory as an example but your browser would complain that it isn't secure. So we recommend to use [`mkcert`] to trust it. To use local CA, you should run: ```sh mkcert -install @@ -19,6 +17,7 @@ mkcert 127.0.0.1 localhost ``` For `rsa` keys use `rsa_private_keys` function instead `pkcs8_private_keys` + ```rs let mut keys = pkcs8_private_keys(key_file).unwrap(); // pkcs8 let mut keys = rsa_private_keys(key_file).unwrap(); // rsa @@ -34,10 +33,9 @@ cargo run # (or ``cargo watch -x run``) # Started http server: 127.0.0.1:8443 ``` -If you prefer reloading you can substitute `cargo watch -x run`. -That requires you install the `cargo-watch` crate. +If you prefer reloading you can substitute `cargo watch -x run`. That requires you install the `cargo-watch` crate. ### web client -- curl: ``curl -v https://127.0.0.1:8443/index.html --compressed -k`` +- curl: `curl -v https://127.0.0.1:8443/index.html --compressed -k` - browser: [https://127.0.0.1:8443/index.html](https://127.0.0.1:8443/index.html) diff --git a/json/json-decode-error/README.md b/json/json-decode-error/README.md index 1d89c87..a323ef3 100644 --- a/json/json-decode-error/README.md +++ b/json/json-decode-error/README.md @@ -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 diff --git a/json/json-validation/README.md b/json/json-validation/README.md index 9e8e7e9..3ecd11f 100644 --- a/json/json-validation/README.md +++ b/json/json-validation/README.md @@ -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` diff --git a/json/json/README.md b/json/json/README.md index 13cb878..581aacd 100644 --- a/json/json/README.md +++ b/json/json/README.md @@ -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` diff --git a/json/jsonrpc/README.md b/json/jsonrpc/README.md index a19ae34..01e27c1 100644 --- a/json/jsonrpc/README.md +++ b/json/jsonrpc/README.md @@ -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 diff --git a/middleware/middleware/README.md b/middleware/middleware/README.md index b32191b..6026dbd 100644 --- a/middleware/middleware/README.md +++ b/middleware/middleware/README.md @@ -28,8 +28,7 @@ A middleware demonstrating how to read out the outgoing response body. ### `simple::SayHi` -A minimal middleware demonstrating the sequence of operations in an actix middleware. -There is a second version of the same middleware using `wrap_fn` which shows how easily a middleware can be implemented in actix. +A minimal middleware demonstrating the sequence of operations in an actix middleware. There is a second version of the same middleware using `wrap_fn` which shows how easily a middleware can be implemented in actix. ## See Also diff --git a/server-sent-events/README.md b/server-sent-events/README.md index 2e2164d..1b4b36b 100644 --- a/server-sent-events/README.md +++ b/server-sent-events/README.md @@ -1,4 +1,5 @@ # actix-sse + Example of server-sent events, aka `EventSource`, with actix web. ```sh @@ -12,9 +13,10 @@ Open http://127.0.0.1:8080/ with a browser, then send events with another HTTP c curl 127.0.0.1:8080/broadcast/my_message ``` -*my_message* should appear in the browser with a timestamp. +_my_message_ should appear in the browser with a timestamp. ## Performance + This implementation can serve thousands of clients on a 2021 MacBook with no problems. Run `node ./benchmark.js` to benchmark your own system: @@ -24,7 +26,8 @@ $ node benchmark.js Connected: 1000, connection time: 201 ms, total broadcast time: 20 ms^C⏎ ``` -### Error *Too many open files* +### Error _Too many open files_ + You may be limited to a maximal number of connections (open file descriptors). Setting maximum number of open file descriptors to 2048: ```sh diff --git a/shutdown-server/README.md b/shutdown-server/README.md index 0859aae..d77c566 100644 --- a/shutdown-server/README.md +++ b/shutdown-server/README.md @@ -3,9 +3,9 @@ Demonstrates how to shutdown the web server in a couple of ways: 1. remotely, via http request - - Created in response to actix/actix-web#1315 + - Created in response to actix/actix-web#1315 1. sending a SIGINT signal to the server (control-c) - - actix-server natively supports SIGINT + - actix-server natively supports SIGINT ## Usage @@ -22,6 +22,6 @@ cargo run --bin shutdown-server ### Available Routes - [GET /hello](http://localhost:8080/hello) - - Regular hello world route + - Regular hello world route - [POST /stop](http://localhost:8080/stop) - - Calling this will shutdown the server and exit + - Calling this will shutdown the server and exit diff --git a/templating/yarte/README.md b/templating/yarte/README.md index 68e91dd..27b4a2c 100644 --- a/templating/yarte/README.md +++ b/templating/yarte/README.md @@ -7,4 +7,5 @@ cd templating/yarte cargo test cargo run ``` + > open `localhost:8080` diff --git a/unix-socket/README.md b/unix-socket/README.md index 19937de..8022d6e 100644 --- a/unix-socket/README.md +++ b/unix-socket/README.md @@ -9,9 +9,6 @@ curl --unix-socket /tmp/actix-uds.socket http://localhost/ Hello world! ``` -Although this will only one thread for handling incoming connections -according to the [documentation](https://actix.github.io/actix-web/actix_web/struct.HttpServer.html#method.bind_uds). +Although this will only one thread for handling incoming connections according to the [documentation](https://actix.github.io/actix-web/actix_web/struct.HttpServer.html#method.bind_uds). -And it does not delete the socket file (`/tmp/actix-uds.socket`) when stopping -the server, so it will fail to start next time you run it unless you delete -the socket file manually. +And it does not delete the socket file (`/tmp/actix-uds.socket`) when stopping the server, so it will fail to start next time you run it unless you delete the socket file manually. diff --git a/websockets/chat-broker/README.md b/websockets/chat-broker/README.md index c720154..0ac50b3 100644 --- a/websockets/chat-broker/README.md +++ b/websockets/chat-broker/README.md @@ -1,26 +1,25 @@ # Websocket chat broker example -This is a different implementation of the -[websocket chat example](https://github.com/actix/examples/tree/master/websockets/chat) +This is a different implementation of the [websocket chat example](https://github.com/actix/examples/tree/master/websockets/chat) Differences: -* Chat Server Actor is a System Service that runs in the same thread as the HttpServer/WS Listener. -* The [actix-broker](https://github.com/Chris-Ricketts/actix-broker) crate is used to facilitate the sending of some messages between the Chat Session and Server Actors where the session does not require a response. -* The Client is not required to send Ping messages. The Chat Server Actor auto-clears dead sessions. +- Chat Server Actor is a System Service that runs in the same thread as the HttpServer/WS Listener. +- The [actix-broker](https://github.com/Chris-Ricketts/actix-broker) crate is used to facilitate the sending of some messages between the Chat Session and Server Actors where the session does not require a response. +- The Client is not required to send Ping messages. The Chat Server Actor auto-clears dead sessions. Possible Improvements: -* Could the Chat Server Actor be simultaneously a System Service (accessible to the Chat Session via the System Registry) and also run in a separate thread? +- Could the Chat Server Actor be simultaneously a System Service (accessible to the Chat Session via the System Registry) and also run in a separate thread? ## Server Chat server listens for incoming tcp connections. Server can access several types of message: -* `/list` - list all available rooms -* `/join name` - join room, if room does not exist, create new one -* `/name name` - set session name -* `some message` - just string, send message to all peers in same room +- `/list` - list all available rooms +- `/join name` - join room, if room does not exist, create new one +- `/name name` - set session name +- `some message` - just string, send message to all peers in same room To start server use command: `cargo run` diff --git a/websockets/chat-tcp/README.md b/websockets/chat-tcp/README.md index 79e19cf..b9f9c6d 100644 --- a/websockets/chat-tcp/README.md +++ b/websockets/chat-tcp/README.md @@ -1,7 +1,6 @@ # Websocket chat example -This is extension of the -[actix chat example](https://github.com/actix/actix/tree/master/examples/chat) +This is extension of the [actix chat example](https://github.com/actix/actix/tree/master/examples/chat) Added features: diff --git a/websockets/chat/README.md b/websockets/chat/README.md index cbf8466..6d3d057 100644 --- a/websockets/chat/README.md +++ b/websockets/chat/README.md @@ -1,27 +1,25 @@ # Websocket chat example -This is extension of the -[actix chat example](https://github.com/actix/actix/tree/master/examples/chat) +This is extension of the [actix chat example](https://github.com/actix/actix/tree/master/examples/chat) Added features: -* Browser WebSocket client -* Chat server runs in separate thread -* Tcp listener runs in separate thread -* Application state is shared with the websocket server and a resource at `/count/` +- Browser WebSocket client +- Chat server runs in separate thread +- Tcp listener runs in separate thread +- Application state is shared with the websocket server and a resource at `/count/` ## Server 1. Chat server listens for incoming tcp connections. Server can access several types of message: -* `/list` - list all available rooms -* `/join name` - join room, if room does not exist, create new one -* `/name name` - set session name -* `some message` - just string, send message to all peers in same room -* client has to send heartbeat `Ping` messages, if server does not receive a heartbeat message for 10 seconds connection gets dropped +- `/list` - list all available rooms +- `/join name` - join room, if room does not exist, create new one +- `/name name` - set session name +- `some message` - just string, send message to all peers in same room +- client has to send heartbeat `Ping` messages, if server does not receive a heartbeat message for 10 seconds connection gets dropped -2. [http://localhost:8080/count/](http://localhost:8080/count/) is a - non-websocket endpoint and will affect and display state. +2. [http://localhost:8080/count/](http://localhost:8080/count/) is a non-websocket endpoint and will affect and display state. To start server use command: `cargo run --bin websocket-chat-server` diff --git a/websockets/echo/README.md b/websockets/echo/README.md index b69a005..b3be85d 100644 --- a/websockets/echo/README.md +++ b/websockets/echo/README.md @@ -25,10 +25,10 @@ cargo run --bin websocket-client ### python client -- ``pip install aiohttp`` -- ``python websocket-client.py`` +- `pip install aiohttp` +- `python websocket-client.py` if ubuntu : -- ``pip3 install aiohttp`` -- ``python3 websocket-client.py`` +- `pip3 install aiohttp` +- `python3 websocket-client.py`