restructure and make data generic
|
@ -785,25 +785,6 @@ name = "json"
|
|||
version = "0.12.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "json-sse"
|
||||
version = "0.0.1"
|
||||
dependencies = [
|
||||
"actix-cors 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"actix-rt 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"actix-web 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"env_logger 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"envy 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"json 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_derive 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_json 1.0.44 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"sled 0.30.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"sse-actix-web 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"tokio 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "kernel32-sys"
|
||||
version = "0.2.2"
|
||||
|
@ -1262,6 +1243,25 @@ dependencies = [
|
|||
"tokio 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sse-server"
|
||||
version = "0.0.1"
|
||||
dependencies = [
|
||||
"actix-cors 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"actix-rt 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"actix-web 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"env_logger 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"envy 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"json 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_derive 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_json 1.0.44 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"sled 0.30.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"sse-actix-web 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"tokio 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.11"
|
||||
|
|
25
Cargo.toml
|
@ -1,4 +1,21 @@
|
|||
[workspace]
|
||||
members = [
|
||||
"json-sse"
|
||||
]
|
||||
[package]
|
||||
name = "sse-server"
|
||||
version = "0.0.1"
|
||||
authors = ["Bevan Hunt <bevan@bevanhunt.com>"]
|
||||
edition = "2018"
|
||||
license = "MIT"
|
||||
|
||||
[dependencies]
|
||||
actix-rt = "1.0.0"
|
||||
actix-web = "2.0.0"
|
||||
actix-cors = "0.2.0"
|
||||
futures = "0.3.1"
|
||||
tokio = "0.2.4"
|
||||
sse-actix-web = "0.7.0"
|
||||
serde = "1.0.103"
|
||||
serde_json = "1.0.44"
|
||||
serde_derive = "1.0.103"
|
||||
json = "0.12.0"
|
||||
sled = "0.30.3"
|
||||
envy = "0.4.0"
|
||||
env_logger = "0.6"
|
||||
|
|
2
Makefile
|
@ -1,4 +1,4 @@
|
|||
build:
|
||||
PORT=8080 cargo run
|
||||
rusty:
|
||||
curl -S -v --header "Content-Type: application/json" POST --data '{"event":"name", "data":{"name":"Rusty"}}' http://localhost:8080/name
|
||||
curl -S -v --header "Content-Type: application/json" POST --data '{"event":"user", "data":{"user":"Rusty"}}' http://localhost:8080/insert
|
|
@ -1,13 +1,9 @@
|
|||
# JSON SSE example using Actix Web
|
||||
# SSE server using Actix Web
|
||||
|
||||
## Build
|
||||
|
||||
- ``` make ```
|
||||
|
||||
- open ``` /client ``` and ``` npm install && npm start ```
|
||||
|
||||
- open ``` localhost:3000 ``` and run ``` make rusty ``` from the command line - you should see the name Rusty
|
||||
|
||||
## Example
|
||||
|
||||
- https://sse-demo.mynextlevel.dev
|
||||
|
|
Before Width: | Height: | Size: 3.8 KiB After Width: | Height: | Size: 3.8 KiB |
Before Width: | Height: | Size: 5.2 KiB After Width: | Height: | Size: 5.2 KiB |
Before Width: | Height: | Size: 9.4 KiB After Width: | Height: | Size: 9.4 KiB |
Before Width: | Height: | Size: 2.6 KiB After Width: | Height: | Size: 2.6 KiB |
|
@ -1,4 +0,0 @@
|
|||
target/*
|
||||
target
|
||||
tmp/*
|
||||
tmp
|
|
@ -1,21 +0,0 @@
|
|||
[package]
|
||||
name = "json-sse"
|
||||
version = "0.0.1"
|
||||
authors = ["Bevan Hunt <bevan@bevanhunt.com>"]
|
||||
edition = "2018"
|
||||
license = "MIT"
|
||||
|
||||
[dependencies]
|
||||
actix-rt = "1.0.0"
|
||||
actix-web = "2.0.0"
|
||||
actix-cors = "0.2.0"
|
||||
futures = "0.3.1"
|
||||
tokio = "0.2.4"
|
||||
sse-actix-web = "0.7.0"
|
||||
serde = "1.0.103"
|
||||
serde_json = "1.0.44"
|
||||
serde_derive = "1.0.103"
|
||||
json = "0.12.0"
|
||||
sled = "0.30.3"
|
||||
envy = "0.4.0"
|
||||
env_logger = "0.6"
|
|
@ -15,15 +15,10 @@ pub struct MyData {
|
|||
db: sled::Db
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
struct Data {
|
||||
user: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
struct JSON {
|
||||
event: String,
|
||||
data: Data,
|
||||
data: serde_json::Value,
|
||||
}
|
||||
|
||||
async fn new_client(data: web::Data<MyData>, broad: web::Data<Mutex<Broadcaster>>) -> impl Responder {
|