Spring Cloud OpenFeign: Difference between revisions
Jump to navigation
Jump to search
Line 52: | Line 52: | ||
</source> | </source> | ||
|} | |} | ||
==Mock REST API== | |||
<source lang="bash"> | |||
mkdir -p ~/Documents/flask-playground/MockApi | |||
python3 -m venv ~/.venv/flask --prompt="Flask" | |||
source ~/.venv/flask/bin/activate | |||
pip install Flask | |||
</source> | |||
<source lang="bash"> | |||
rm rf ~/Documents/flask-playground/MockApi/* | |||
cat << EOF | tee ~/Documents/flask-playground/MockApi/__init__.py >/dev/null | |||
from flask import Flask, request, json, jsonify | |||
app = Flask(__name__) | |||
app.json.sort_keys = False | |||
companies = [{'id': 1, 'name': 'Chorke', 'concern': False}, {'id': 2, 'name': 'Academia', 'concern': True}] | |||
@app.route("/api/v1/companies") | |||
def data(): | |||
lang_code = request.args.get('lang_code') | |||
print(f'lang_code: {lang_code}!') | |||
#return json.dumps(companies) | |||
return jsonify(companies) | |||
if __name__ == "__main__": | |||
app.run(host='127.0.0.1', port=1983) | |||
EOF | |||
python ~/Documents/flask-playground/MockApi/__init__.py | |||
</source> | |||
<source lang="bash"> | |||
curl -k http://127.0.0.1:1983/api/v1/companies?lang_code=EN | |||
curl -i http://127.0.0.1:1983/api/v1/companies?lang_code=EN | |||
http GET 127.0.0.1:1983/api/v1/companies?lang_code=EN --pretty=colors | |||
</source> | |||
==References== | ==References== |
Revision as of 11:07, 9 February 2024
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!--
others dependencies
-->
</dependencies>
</dependencyManagement>
|
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-okhttp</artifactId>
</dependency>
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-httpclient</artifactId>
</dependency>
</dependencies>
|
| |
timeout 60 telnet localhost 1983 \
;printf '\n'
|
nc -w 60 localhost 1983 \
;printf '\n'
|
Mock REST API
mkdir -p ~/Documents/flask-playground/MockApi
python3 -m venv ~/.venv/flask --prompt="Flask"
source ~/.venv/flask/bin/activate
pip install Flask
rm rf ~/Documents/flask-playground/MockApi/*
cat << EOF | tee ~/Documents/flask-playground/MockApi/__init__.py >/dev/null
from flask import Flask, request, json, jsonify
app = Flask(__name__)
app.json.sort_keys = False
companies = [{'id': 1, 'name': 'Chorke', 'concern': False}, {'id': 2, 'name': 'Academia', 'concern': True}]
@app.route("/api/v1/companies")
def data():
lang_code = request.args.get('lang_code')
print(f'lang_code: {lang_code}!')
#return json.dumps(companies)
return jsonify(companies)
if __name__ == "__main__":
app.run(host='127.0.0.1', port=1983)
EOF
python ~/Documents/flask-playground/MockApi/__init__.py
curl -k http://127.0.0.1:1983/api/v1/companies?lang_code=EN
curl -i http://127.0.0.1:1983/api/v1/companies?lang_code=EN
http GET 127.0.0.1:1983/api/v1/companies?lang_code=EN --pretty=colors
References
| ||