github.com/lastbackend/toolkit@v0.0.0-20241020043710-cafa37b95aad/examples/README.md (about) 1 # Examples 2 3 ### 1. GRPC service 4 5 ---- 6 7 Follow these run example: 8 9 Run the GRPC service: 10 11 ```console 12 go run service/main.go 13 ``` 14 15 if you see it: 16 ```console 17 ... 18 server listening at [::]:50005 19 ... 20 ``` 21 22 _Great, you have succeeded!_ 23 24 25 ### 2. HTTP Gateway 26 27 ---- 28 29 Follow these run example: 30 31 Run the Gateway server: 32 33 ```console 34 env GTW_GATEWAY_SERVER_PORT=8082 go run main.go 35 ``` 36 37 Run gRPC Hello World Server 38 39 ```console 40 go run helloworld/main.go 41 ``` 42 43 Make a request to the Hello World Server 44 45 ```console 46 curl -i -X POST http://localhost:8082/hello -H 'Content-Type: application/json' --data '{"name":"world"}' 47 48 Response: 49 HTTP/1.1 200 OK 50 Content-Type: application/json 51 Date: Wed, 01 Feb 2023 20:40:03 GMT 52 Content-Length: 25 53 54 {"message":"Hello world"} 55 ``` 56 57 Call custom handler 58 59 ```console 60 curl -i -X GET http://localhost:8080/health -H 'Content-Type: application/json' 61 62 Response: 63 HTTP/1.1 200 OK 64 Content-Type: application/json 65 Date: Wed, 01 Feb 2023 20:44:57 GMT 66 Content-Length: 15 67 68 {"alive": true} 69 ``` 70 71 72 ### 3. WSS Proxy 73 74 ---- 75 76 Follow these run example: 77 78 Run the WSS server: 79 80 ```console 81 go run wss/main.go 82 ``` 83 84 Run gRPC Hello World Server 85 86 ```console 87 go run helloworld/main.go 88 ``` 89 90 Make a request to the Hello World Server 91 92 ```console 93 curl -i -X POST http://localhost:8080/hello -H 'Content-Type: application/json' --data '{"name":"world"}' 94 95 Response: 96 HTTP/1.1 200 OK 97 Content-Type: application/json 98 Date: Wed, 01 Feb 2023 20:40:03 GMT 99 Content-Length: 24 100 101 {"message":"Hello world"} 102 ``` 103 104 Call wss events handler 105 106 ```console 107 websocat ws://localhost:8008/events 108 {"type":"HelloWorld","payload":{"name":"world"}} 109 {"message":"Hello world"} 110 ``` 111 112 113 ### 4. HTTP server 114 115 ---- 116 117 Follow these run example: 118 119 Run the HTTP server: 120 121 ```console 122 env LB_HTTP_SERVER_PORT=8082 go run http/main.go 123 ``` 124 125 Make a request to the HTTP Server 126 127 ```console 128 curl -X GET 'http://localhost:8082/health' 129 130 Response: 131 HTTP/1.1 200 OK 132 Content-Type: application/json 133 Date: Wed, 01 Feb 2023 20:44:57 GMT 134 Content-Length: 15 135 136 {"alive": true} 137 ```