|
| 1 | +# Legacy HTTP 0.x Examples |
| 2 | + |
| 3 | +This directory contains examples for Smithy-rs using HTTP 0.x (hyper 0.14, http 0.2). These examples use the legacy HTTP stack with `aws-smithy-legacy-http` and `aws-smithy-legacy-http-server`. |
| 4 | + |
| 5 | +For HTTP 1.x examples (hyper 1.x, http 1.x), see the parent [examples](../) directory. |
| 6 | + |
| 7 | +## Building |
| 8 | + |
| 9 | +### 1. Generate the SDKs |
| 10 | + |
| 11 | +From this directory, run: |
| 12 | + |
| 13 | +```bash |
| 14 | +make codegen |
| 15 | +``` |
| 16 | + |
| 17 | +This will generate: |
| 18 | +- `pokemon-service-server-sdk-http0x` - Server SDK using HTTP 0.x |
| 19 | +- `pokemon-service-client-http0x` - Client SDK using HTTP 0.x |
| 20 | + |
| 21 | +The generated SDKs are copied to: |
| 22 | +- `pokemon-service-server-sdk/` |
| 23 | +- `pokemon-service-client/` |
| 24 | + |
| 25 | +### 2. Build all examples |
| 26 | + |
| 27 | +```bash |
| 28 | +cargo build |
| 29 | +``` |
| 30 | + |
| 31 | +Or to check without building artifacts: |
| 32 | + |
| 33 | +```bash |
| 34 | +cargo check |
| 35 | +``` |
| 36 | + |
| 37 | +## Running the Examples |
| 38 | + |
| 39 | +### Start the Pokemon Service |
| 40 | + |
| 41 | +In one terminal, start the server: |
| 42 | + |
| 43 | +```bash |
| 44 | +cargo run --bin pokemon-service |
| 45 | +``` |
| 46 | + |
| 47 | +The server will start on `http://localhost:13734` |
| 48 | + |
| 49 | +### Run Client Examples |
| 50 | + |
| 51 | +In another terminal, from the `pokemon-service-client-usage/` directory: |
| 52 | + |
| 53 | +```bash |
| 54 | +cd pokemon-service-client-usage |
| 55 | +cargo run --example simple-client |
| 56 | +``` |
| 57 | + |
| 58 | +#### Available Client Examples |
| 59 | + |
| 60 | +| Example | Description | |
| 61 | +|---------|-------------| |
| 62 | +| `simple-client` | Basic client usage - creates a client and calls an operation | |
| 63 | +| `endpoint-resolver` | Custom endpoint resolver configuration | |
| 64 | +| `handling-errors` | Sending input parameters and handling errors | |
| 65 | +| `custom-header` | Adding custom headers to requests | |
| 66 | +| `custom-header-using-interceptor` | Accessing operation name in an interceptor | |
| 67 | +| `response-header-interceptor` | Getting operation name and accessing response before deserialization | |
| 68 | +| `use-config-bag` | Using the property bag to pass data across interceptors | |
| 69 | +| `retry-customize` | Customizing retry settings | |
| 70 | +| `timeout-config` | Configuring timeouts | |
| 71 | +| `mock-request` | Using custom HttpConnector for mock responses | |
| 72 | +| `trace-serialize` | Tracing request/response during serialization | |
| 73 | +| `client-connector` | Changing TLS configuration | |
| 74 | + |
| 75 | +To list all available examples: |
| 76 | + |
| 77 | +```bash |
| 78 | +cd pokemon-service-client-usage |
| 79 | +cargo run --example |
| 80 | +``` |
| 81 | + |
| 82 | +### Other Services |
| 83 | + |
| 84 | +#### Pokemon Service with TLS |
| 85 | + |
| 86 | +```bash |
| 87 | +cargo run --bin pokemon-service-tls |
| 88 | +``` |
| 89 | + |
| 90 | +#### Pokemon Service on AWS Lambda |
| 91 | + |
| 92 | +```bash |
| 93 | +cargo run --bin pokemon-service-lambda |
| 94 | +``` |
| 95 | + |
| 96 | +## Project Structure |
| 97 | + |
| 98 | +``` |
| 99 | +legacy/ |
| 100 | +├── pokemon-service/ # Main HTTP service implementation |
| 101 | +├── pokemon-service-tls/ # TLS-enabled service |
| 102 | +├── pokemon-service-lambda/ # AWS Lambda service |
| 103 | +├── pokemon-service-common/ # Shared service logic |
| 104 | +├── pokemon-service-client-usage/ # Client usage examples |
| 105 | +├── pokemon-service-server-sdk/ # Generated server SDK (HTTP 0.x) |
| 106 | +└── pokemon-service-client/ # Generated client SDK (HTTP 0.x) |
| 107 | +``` |
| 108 | + |
| 109 | +## Key Dependencies (HTTP 0.x) |
| 110 | + |
| 111 | +- `hyper = "0.14"` |
| 112 | +- `http = "0.2"` |
| 113 | +- `aws-smithy-legacy-http` |
| 114 | +- `aws-smithy-legacy-http-server` |
| 115 | + |
| 116 | +## Regenerating SDKs |
| 117 | + |
| 118 | +If you need to regenerate the SDKs from scratch: |
| 119 | + |
| 120 | +```bash |
| 121 | +rm -rf pokemon-service-server-sdk pokemon-service-client |
| 122 | +make codegen |
| 123 | +``` |
| 124 | + |
| 125 | +## Testing |
| 126 | + |
| 127 | +Run all tests: |
| 128 | + |
| 129 | +```bash |
| 130 | +cargo test |
| 131 | +``` |
| 132 | + |
| 133 | +Run tests for a specific package: |
| 134 | + |
| 135 | +```bash |
| 136 | +cargo test -p pokemon-service |
| 137 | +``` |
| 138 | + |
| 139 | +## Troubleshooting |
| 140 | + |
| 141 | +### Port Already in Use |
| 142 | + |
| 143 | +If port 13734 is already in use, you can specify a different port: |
| 144 | + |
| 145 | +```bash |
| 146 | +cargo run --bin pokemon-service -- --port 8080 |
| 147 | +``` |
| 148 | + |
| 149 | +Then update the client examples to use the new port by setting the environment variable: |
| 150 | + |
| 151 | +```bash |
| 152 | +POKEMON_SERVICE_URL=http://localhost:8080 cargo run --example simple-client |
| 153 | +``` |
| 154 | + |
| 155 | +### SDK Generation Issues |
| 156 | + |
| 157 | +If the generated SDKs have issues, try cleaning and regenerating: |
| 158 | + |
| 159 | +```bash |
| 160 | +# Clean generated SDKs |
| 161 | +rm -rf pokemon-service-server-sdk pokemon-service-client |
| 162 | + |
| 163 | +# Clean gradle cache |
| 164 | +cd ../.. |
| 165 | +./gradlew clean |
| 166 | + |
| 167 | +# Regenerate |
| 168 | +cd examples/legacy |
| 169 | +make codegen |
| 170 | +``` |
| 171 | + |
| 172 | +## Migration to HTTP 1.x |
| 173 | + |
| 174 | +For new projects, we recommend using the HTTP 1.x examples in the parent [examples](../) directory. These legacy examples are maintained for backward compatibility and for projects that need to use the HTTP 0.x stack. |
| 175 | + |
| 176 | +The main differences: |
| 177 | +- HTTP 1.x uses `hyper 1.x`, `http 1.x` |
| 178 | +- HTTP 1.x uses `aws-smithy-http`, `aws-smithy-http-server` (not legacy versions) |
| 179 | +- HTTP 1.x has better performance and modern async runtime support |
0 commit comments