Skip to content

Commit c861836

Browse files
Update README (#2)
* Alternate take to Docker networking That should hopefully fix networking issues on non-Linux machines * Introduce FACTORY_IP_ADDRESS in the examples * Remove application responses from README * Update README.md * Some more README updates * Add a note about UUIDv4 values --------- Co-authored-by: PiPPiPPoland <114883993+PiPPiPPoland@users.noreply.github.com>
1 parent 0e91ee7 commit c861836

File tree

2 files changed

+46
-111
lines changed

2 files changed

+46
-111
lines changed

README.md

Lines changed: 45 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -16,178 +16,113 @@ docker build -t factory:local .
1616
Once you have an image built, run it like
1717

1818
```sh
19-
docker run --rm --name factory --network=host -p 8000:8000 factory:local
19+
docker run --rm --name factory -p 8000:8000 factory:local
2020
```
2121

2222
This snippet is intended just for testing the app, it is usually not a good
2323
idea to run any containers like that in production.
2424

2525
## Testing it
2626

27-
In another terminal window simple `curl` can be used to test the application, e.g.
27+
By default Docker container would probably start in `bridge` network mode (that
28+
depends on your configuration), to find its IP address open another terminal and
29+
run something like.
30+
31+
```sh
32+
export FACTORY_IP_ADDRESS=$( docker inspect factory | jq -r '.[].NetworkSettings.IPAddress' )
33+
```
34+
35+
This should give you an important information about the IP of the container. And
36+
that will be available as the `FACTORY_IP_ADDRESS` environment variable. Now with
37+
that variable available (so in the same terminal window), you can run some `curl`
38+
commands to test the application.
39+
40+
Note: If your Docker environment blocks direct access to the containers, you
41+
could run each `curl` command in a container. The following code snippets would
42+
still be relavant if you created an alias, e.g.
43+
44+
```sh
45+
alias curl='docker run --rm curlimages/curl'
46+
```
2847

2948
### Creating new materials (oxygen, hydrogen and sulphur)
3049
```sh
31-
curl -X POST -H "Content-Type: application/json" \
50+
curl -s -X POST -H "Content-Type: application/json" \
3251
-d '{"name": "Oxygen", "quantity_unit": "mole"}' \
33-
http://localhost:8000/materials/
52+
http://${FACTORY_IP_ADDRESS}:8000/materials/
3453

35-
curl -X POST -H "Content-Type: application/json" \
54+
curl -s -X POST -H "Content-Type: application/json" \
3655
-d '{"name": "Hydrogen", "quantity_unit": "mole"}' \
37-
http://localhost:8000/materials/
56+
http://${FACTORY_IP_ADDRESS}:8000/materials/
3857

39-
curl -X POST -H "Content-Type: application/json" \
58+
curl -s -X POST -H "Content-Type: application/json" \
4059
-d '{"name": "Sulphur", "quantity_unit": "mole"}' \
41-
http://localhost:8000/materials/
60+
http://${FACTORY_IP_ADDRESS}:8000/materials/
4261
```
4362

4463
### Listing materials
4564
```sh
46-
curl -s http://localhost:8000/materials/ | jq
47-
[
48-
{
49-
"name": "Oxygen",
50-
"slug": "oxygen",
51-
"quantity_unit": "mole",
52-
"id": "699139c4-eb11-4815-9021-2c8f66b38d5f"
53-
},
54-
{
55-
"name": "Hydrogen",
56-
"slug": "hydrogen",
57-
"quantity_unit": "mole",
58-
"id": "c18605cd-3e1e-4898-8192-1da5662bc30a"
59-
},
60-
{
61-
"name": "Sulphur",
62-
"slug": "sulphur",
63-
"quantity_unit": "mole",
64-
"id": "f49a9fff-8345-41cb-934f-f75adc3161b5"
65-
}
66-
]
65+
curl -s http://${FACTORY_IP_ADDRESS}:8000/materials/ | jq
6766
```
6867

6968
### Updating a material
7069
```sh
71-
curl -X PATCH -H "Content-Type: application/json" \
70+
curl -s -X PATCH -H "Content-Type: application/json" \
7271
-d '{"quantity_unit": "µg"}' \
73-
http://localhost:8000/materials/sulphur
72+
http://${FACTORY_IP_ADDRESS}:8000/materials/sulphur
7473
```
7574

7675
### Fetching information about a single material
7776
```sh
78-
curl -s http://localhost:8000/materials/sulphur | jq
79-
{
80-
"name": "Sulphur",
81-
"slug": "sulphur",
82-
"quantity_unit": "µg",
83-
"id": "f49a9fff-8345-41cb-934f-f75adc3161b5",
84-
"created_at": "2025-06-17T07:25:13",
85-
"boms": [],
86-
"stock": [],
87-
"products": []
88-
}
77+
curl -s http://${FACTORY_IP_ADDRESS}:8000/materials/sulphur | jq
8978
```
9079

9180
### Removing a material
9281
```sh
93-
curl -X DELETE http://localhost:8000/materials/sulphur
82+
curl -s -X DELETE http://${FACTORY_IP_ADDRESS}:8000/materials/sulphur
9483
```
9584

9685
### Creating a warehouse
9786
```sh
98-
curl -X POST -H "Content-Type: application/json" \
87+
curl -s -X POST -H "Content-Type: application/json" \
9988
-d '{"name": "Chemicals-1", "location": "Wien", "max_capacity": 1000000}' \
100-
http://localhost:8000/warehouses/
89+
http://${FACTORY_IP_ADDRESS}:8000/warehouses/
10190
```
10291

10392
other operations look just like operations on materials, e.g. fetching
10493
information about a single warehouse would be
10594

10695
```sh
107-
curl -s http://localhost:8000/warehouses/chemicals-1 | jq
108-
{
109-
"name": "Chemicals-1",
110-
"slug": "chemicals-1",
111-
"location": "Wien",
112-
"capacity": 1000000,
113-
"max_capacity": 1000000,
114-
"id": "ad02b895-ea98-4bd5-a889-7869f3e521fb",
115-
"created_at": "2025-06-17T07:28:47",
116-
"stock": []
117-
}
96+
curl -s http://${FACTORY_IP_ADDRESS}:8000/warehouses/chemicals-1 | jq
11897
```
11998

12099
### Delivery process
121100
```sh
122-
curl -X POST -H "Content-Type: application/json" \
101+
curl -s -X POST -H "Content-Type: application/json" \
123102
-d '{"warehouse_id": "ad02b895-ea98-4bd5-a889-7869f3e521fb", \
124-
"positions": [{"material_id": "699139c4-eb11-4815-9021-2c8f66b38d5f",
103+
"positions": [{"material_id": "699139c4-eb11-4815-9021-2c8f66b38d5f", \
125104
"quantity": 10}, {"material_id": "c18605cd-3e1e-4898-8192-1da5662bc30a", \
126105
"quantity": 20}]}' \
127-
http://localhost:8000/delivery/
106+
http://${FACTORY_IP_ADDRESS}:8000/delivery/
128107
```
129108

109+
Note: The `warehouse_id` and `material_id`s values (UUIDv4) are quoted above
110+
only by way of example, they are pseudo-random values so will be different
111+
in each environment.
112+
130113
Delivered materials stored in a warehouse will diminish its capacity, so after
131114
testing a delivery something will change, e.g.
132115

133116
```sh
134-
curl -s http://localhost:8000/warehouses/chemicals-1 | jq
135-
{
136-
"name": "Chemicals-1",
137-
"slug": "chemicals-1",
138-
"location": "Wien",
139-
"capacity": 999970,
140-
"max_capacity": 1000000,
141-
"id": "ad02b895-ea98-4bd5-a889-7869f3e521fb",
142-
"created_at": "2025-06-17T07:28:47",
143-
"stock": [
144-
{
145-
"id": "d9b1f90d-8559-46e5-b6c3-546d16666aa0",
146-
"quantity": 10,
147-
"material_name": "Oxygen",
148-
"material_slug": "oxygen"
149-
},
150-
{
151-
"id": "31ed7603-43f2-41a9-a817-10ce54fbdf29",
152-
"quantity": 20,
153-
"material_name": "Hydrogen",
154-
"material_slug": "hydrogen"
155-
}
156-
]
157-
}
117+
curl -s http://${FACTORY_IP_ADDRESS}:8000/warehouses/chemicals-1 | jq
158118
```
159119

160120
```sh
161-
curl -s http://localhost:8000/materials/oxygen | jq
162-
{
163-
"name": "Oxygen",
164-
"slug": "oxygen",
165-
"quantity_unit": "mole",
166-
"id": "699139c4-eb11-4815-9021-2c8f66b38d5f",
167-
"created_at": "2025-06-17T07:24:50",
168-
"boms": [],
169-
"stock": [
170-
{
171-
"id": "d9b1f90d-8559-46e5-b6c3-546d16666aa0",
172-
"warehouse_id": "ad02b895-ea98-4bd5-a889-7869f3e521fb",
173-
"quantity": 10,
174-
"warehouse_name": "Chemicals-1",
175-
"warehouse_slug": "chemicals-1"
176-
},
177-
{
178-
"id": "ca6bd72a-48ec-4a29-a3d9-545d09f8b7e9",
179-
"warehouse_id": "daae3903-dd42-473b-a160-0a838ccf65f0",
180-
"quantity": 10000,
181-
"warehouse_name": "Chemicals-2",
182-
"warehouse_slug": "chemicals-2"
183-
}
184-
],
185-
"products": []
186-
}
121+
curl -s http://${FACTORY_IP_ADDRESS}:8000/materials/oxygen | jq
187122
```
188123

189124
### Further testing
190125

191126
There are other endpoints, not described in this short README file. Feel
192127
free to investigate them on your own by browsing files in the `routers/`
193-
directory.
128+
directory.

main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def create_application() -> app.FactoryApp:
5151

5252

5353
def main() -> None: # noqa: D103
54-
uvicorn.run("main:create_application", host="localhost", port=8000, reload=True)
54+
uvicorn.run("main:create_application", host="0.0.0.0", port=8000, reload=True)
5555

5656

5757
if __name__ == "__main__":

0 commit comments

Comments
 (0)