RESTful 마이크로서비스 모의 방법
17736 단어 microservicesmockingwebdevrest
최근에 저는 Rhino라는 간단한 API 목킹 서비스를 만들었습니다. 때로는 아직 준비되지 않았거나 데이터를 설정하고 채우는 데 많은 노력이 필요하거나 아직 준비되지 않은 단일 페이지 애플리케이션 및 백엔드에 대한 백엔드가 필요한 RESTful 웹 서비스와 통합해야 하기 때문입니다.
클리번 / 코뿔소
❄️ HTTP 조롱 및 디버깅 서비스.
코뿔소
HTTP 모의 및 디버깅 서비스
Rhino는 HTTP 모의 및 디버깅 서비스입니다. 테스트 및 디버깅 목적으로 HTTP 웹 서비스를 쉽게 조롱할 수 있습니다. 또한 높은 대기 시간과 장애를 시뮬레이션하여 서비스가 장애를 견디고 복구할 수 있는 기능을 갖도록 할 수 있습니다. CORS(교차 원본 리소스 공유)를 지원하므로 단일 페이지 애플리케이션의 백엔드로 사용할 수 있습니다.
선적 서류 비치
용법
가져오기the latest binary.
$ curl -sL https://github.com/Clivern/Rhino/releases/download/x.x.x/Rhino_x.x.x_OS_x86_64.tar.gz | tar xz
Create the config file config.prod.json
{
"app": {
"mode": "prod or dev"
"port": "8080",
"domain": "http://127.0.0.1:8080",
"tls": {
"status": "off",
"pemPath": "/cert/server.pem",
"keyPath": "/cert/server.key"
}
},
"mock": [
{
"path": "/api/v2/service1/mock/:id",
"request": {
"method": "get"
…
Rhino enables easy mocking of any HTTP web service for testing and debugging purposes. Also it can simulate high latencies and failures to make sure your services have the capability to withstand and recover from failures. It supports cross-origin resource sharing (CORS) so it can be used as a backend for single page applications.
Rhino를 로컬에서 실행하려면:
- You will have to download one of the binaries from this page https://github.com/Clivern/Rhino/releases and make it globally executable.
- Create a config file
{
"app": {
"mode": "prod",
"port": "8080",
"domain": "http://127.0.0.1:8080",
"tls": {
"status": "off",
"pemPath": "/cert/server.pem",
"keyPath": "/cert/server.key"
}
},
"mock": [
{
"path": "/api/v2/service1/item",
"request": {
"method": "get"
},
"response": {
"statusCode": 200,
"headers": [
{"key": "Content-Type", "value": "application/json"}
],
"body": "{\"action\": \"list\"}"
},
"chaos": {
"latency": "0s",
"failRate": "0%"
}
},
{
"path": "/api/v2/service1/item",
"request": {
"method": "post"
},
"response": {
"statusCode": 200,
"headers": [
{"key": "Content-Type", "value": "application/json"}
],
"body": "{\"action\": \"create\"}"
},
"chaos": {
"latency": "0s",
"failRate": "0%"
}
},
{
"path": "/api/v2/service1/item/:id",
"request": {
"method": "get"
},
"response": {
"statusCode": 200,
"headers": [
{"key": "Content-Type", "value": "application/json"}
],
"body": "{\"id\": \":id\", \"action\": \"get one\"}"
},
"chaos": {
"latency": "0s",
"failRate": "0%"
}
},
{
"path": "/api/v2/service1/item/:id",
"request": {
"method": "put"
},
"response": {
"statusCode": 200,
"headers": [
{"key": "Content-Type", "value": "application/json"}
],
"body": "{\"id\": \":id\", \"action\": \"update\"}"
},
"chaos": {
"latency": "0s",
"failRate": "0%"
}
},
{
"path": "/api/v2/service1/item/:id",
"request": {
"method": "delete"
},
"response": {
"statusCode": 200,
"headers": [
{"key": "Content-Type", "value": "application/json"}
],
"body": "{\"id\": \":id\", \"action\": \"delete\"}"
},
"chaos": {
"latency": "0s",
"failRate": "0%"
}
}
],
"debug": [
{
"path": "/api/debug",
"chaos": {
"latency": "0s",
"failRate": "0%"
}
}
],
"log": {
"level": "info",
"output": "stdout",
"format": "json"
}
}
$ rhino serve -c config.json
➜ ~ curl -X POST "http://127.0.0.1:8080/api/v2/service1/item"
{"action": "create"}
➜ ~ curl -X GET "http://127.0.0.1:8080/api/v2/service1/item"
{"action": "list"}
➜ ~ curl -X GET "http://127.0.0.1:8080/api/v2/service1/item/1"
{"id": "1", "action": "get one"}
➜ ~ curl -X PUT "http://127.0.0.1:8080/api/v2/service1/item/1"
{"id": "1", "action": "update"}
➜ ~ curl -X DELETE "http://127.0.0.1:8080/api/v2/service1/item/1"
{"id": "1", "action": "delete"}
docker와 docker compose로 Rhino를 실행하려면:
리포지토리를 닫고 단순 또는 고급 설정을 사용하십시오.
# Simple setup
$ git clone https://github.com/Clivern/Rhino.git
$ cd Rhino/deployment/basic/docker-compose
$ docker-compose up -d
# In case you want to visualize incoming requests with grafana
$ git clone https://github.com/Clivern/Rhino.git
$ cd Rhino/deployment/advanced/docker-compose
$ docker-compose up -d
Rhino는 끝점 정의에서 사용할 수 있는 많은 가짜 데이터 플래그를 지원합니다.
AnyOf: @fake(:anyof[A||B||C||D])
Latitude: @fake(:lat)
Longitude: @fake(:long)
CreditCardNumber: @fake(:cc_number)
CreditCardType: @fake(:cc_type)
Email: @fake(:email)
DomainName: @fake(:domain_name)
IPV4: @fake(:ipv4)
IPV6: @fake(:ipv6)
Password: @fake(:password)
PhoneNumber: @fake(:phone_number)
MacAddress: @fake(:mac_address)
URL: @fake(:url)
UserName: @fake(:username)
TollFreeNumber: @fake(:toll_free_number)
E164PhoneNumber: @fake(:e_164_phone_number)
TitleMale: @fake(:title_male)
TitleFemale: @fake(:title_female)
FirstName: @fake(:first_name)
FirstNameMale: @fake(:first_name_male)
FirstNameFemale: @fake(:first_name_female)
LastName: @fake(:last_name)
Name: @fake(:name)
UnixTime: @fake(:unix_time)
Date: @fake(:date)
Time: @fake(:time)
MonthName: @fake(:month_name)
Year: @fake(:year)
DayOfWeek: @fake(:day_of_week)
DayOfMonth: @fake(:day_of_month)
Timestamp: @fake(:timestamp)
Century: @fake(:century)
TimeZone: @fake(:timezone)
TimePeriod: @fake(:time_period)
Word: @fake(:word)
Sentence: @fake(:sentence)
Paragraph: @fake(:paragraph)
Currency: @fake(:currency)
Amount: @fake(:amount)
AmountWithCurrency: @fake(:amount_with_currency)
UUIDHypenated: @fake(:uuid_hyphenated)
UUID: @fake(:uuid_digit)
모두 즐거운 코딩하세요! ❤️
Reference
이 문제에 관하여(RESTful 마이크로서비스 모의 방법), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/clivern/how-to-mock-a-restful-microservices-385o텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)