-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from tayyebi/patch-1
Added _run with docker_ method to the guide.
- Loading branch information
Showing
1 changed file
with
106 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,114 +1,116 @@ | ||
### this is just very simple microserve example | ||
# An example of implementing a micro-service architecture | ||
|
||
in this example we have two microserve : | ||
Current example demonstrates two micro-services known as `core` and `ecommerce` located in directories with same naming, with basic API functionality in between. | ||
|
||
- one named `core` which includes `user` and `country` schema with just two action know as `addCountry` and `adduser`. | ||
- you can run this server by runnig below line on `core/` folder: | ||
```bash | ||
deno run -A mod.ts | ||
``` | ||
this service respond to `HTTP POST` request to `http://localhost:8080/lesan` with this `JSON` on request body : | ||
```bash | ||
{ | ||
"contents": "dynamic", | ||
"wants": { | ||
"model": "user", | ||
"act": "addUser" | ||
}, | ||
"details": { | ||
"set": { | ||
"name": "Seyyedeh Sare Hosseini", | ||
"address": "Iran, Hamedan", | ||
"age": 5 | ||
}, | ||
"get": { | ||
"age": 1, | ||
"address": 1 | ||
} | ||
} | ||
## Running this example | ||
To run each example, navigate to corresponding directories (using `cd ecommerce` or `cd core` command) and choose one of the prefered methods below: | ||
### Method 1: OS Shell | ||
```bash | ||
deno run -A mod.ts | ||
``` | ||
### Method 2: Docker container | ||
```bash | ||
docker run -it -v "${PWD}:/app" denoland/deno deno run --allow-all /app/mod.ts | ||
``` | ||
|
||
The `core` microservice respond to `HTTP POST` request to `http://localhost:8080/lesan` with this `JSON` on request body mapped to its only actions defined (`addCountry` and `addUser`): | ||
```bash | ||
{ | ||
"contents": "dynamic", | ||
"wants": { | ||
"model": "user", | ||
"act": "addUser" | ||
}, | ||
"details": { | ||
"set": { | ||
"name": "Seyyedeh Sare Hosseini", | ||
"address": "Iran, Hamedan", | ||
"age": 5 | ||
}, | ||
"get": { | ||
"age": 1, | ||
"address": 1 | ||
} | ||
``` | ||
and | ||
```bash | ||
{ | ||
"contents": "dynamic", | ||
"wants": { | ||
"model": "country", | ||
"act": "addCountry" | ||
}, | ||
"details": { | ||
"set": { | ||
"name": "iran", | ||
"description": "Nice and great country" | ||
}, | ||
"get": { | ||
"name": 1 | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
and | ||
```bash | ||
{ | ||
"contents": "dynamic", | ||
"wants": { | ||
"model": "country", | ||
"act": "addCountry" | ||
}, | ||
"details": { | ||
"set": { | ||
"name": "iran", | ||
"description": "Nice and great country" | ||
}, | ||
"get": { | ||
"name": 1 | ||
} | ||
``` | ||
it also can respond to `ecommerce` service request by adding `service` key to JSON body : | ||
```bash | ||
{ | ||
"service": "ecommerce", | ||
"contents": "dynamic", | ||
"wants": { | ||
"model": "wareType", | ||
"act": "addWareType" | ||
} | ||
} | ||
``` | ||
it also can respond to `ecommerce` service request by adding `service` key to JSON body : | ||
```bash | ||
{ | ||
"service": "ecommerce", | ||
"contents": "dynamic", | ||
"wants": { | ||
"model": "wareType", | ||
"act": "addWareType" | ||
}, | ||
"details": { | ||
"set": { | ||
"name": "digital", | ||
"description": "digital stuff like phone and ..." | ||
}, | ||
"details": { | ||
"set": { | ||
"name": "digital", | ||
"description": "digital stuff like phone and ..." | ||
}, | ||
"get": { | ||
"name": 1 | ||
} | ||
"get": { | ||
"name": 1 | ||
} | ||
} | ||
``` | ||
- another named `ecommerce` which includes `ware` and `wareType` schema with two action `addWare` and `addWareType`. | ||
- you can run this server by runnig below line on `ecommerce/` folder: | ||
```bash | ||
deno run -A mod.ts | ||
``` | ||
this service respond to `HTTP POST` request to `http://localhost:8585/lesan` with this `JSON` on request body : | ||
```bash | ||
{ | ||
"contents": "dynamic", | ||
"wants": { | ||
"model": "wareType", | ||
"act": "addWareType" | ||
} | ||
} | ||
``` | ||
In the other case `ecommerce` which includes `ware` and `wareType` schema with two action `addWare` and `addWareType`. | ||
this service respond to `HTTP POST` request to `http://localhost:8585/lesan` with this `JSON` on request body : | ||
```bash | ||
{ | ||
"contents": "dynamic", | ||
"wants": { | ||
"model": "wareType", | ||
"act": "addWareType" | ||
}, | ||
"details": { | ||
"set": { | ||
"name": "digital", | ||
"description": "digital stuff like phone and ..." | ||
}, | ||
"details": { | ||
"set": { | ||
"name": "digital", | ||
"description": "digital stuff like phone and ..." | ||
}, | ||
"get": { | ||
"name": 1 | ||
} | ||
"get": { | ||
"name": 1 | ||
} | ||
} | ||
``` | ||
and | ||
```bash | ||
{ | ||
"contents": "dynamic", | ||
"wants": { | ||
"model": "ware", | ||
"act": "addWare" | ||
} | ||
} | ||
``` | ||
and | ||
```bash | ||
{ | ||
"contents": "dynamic", | ||
"wants": { | ||
"model": "ware", | ||
"act": "addWare" | ||
}, | ||
"details": { | ||
"set": { | ||
"name": "GLX phone", | ||
"brand": "GLX", | ||
"price": 159 | ||
}, | ||
"details": { | ||
"set": { | ||
"name": "GLX phone", | ||
"brand": "GLX", | ||
"price": 159 | ||
}, | ||
"get": { | ||
"name": 1 | ||
"price": 1 | ||
} | ||
"get": { | ||
"name": 1 | ||
"price": 1 | ||
} | ||
} | ||
``` | ||
} | ||
} | ||
``` |