


{"id":4455,"date":"2025-01-02T00:25:45","date_gmt":"2025-01-02T00:25:45","guid":{"rendered":"https:\/\/yininit.nl\/?post_type=blossom-portfolio&#038;p=4455"},"modified":"2025-01-02T22:21:39","modified_gmt":"2025-01-02T22:21:39","slug":"inrichting-stap-3-railway-hosting-en-github-codespaces","status":"publish","type":"blossom-portfolio","link":"https:\/\/yininit.nl\/index.php\/portfolio\/inrichting-stap-3-railway-hosting-en-github-codespaces\/","title":{"rendered":"Inrichting &#8211; Stap 3: Railway (Hosting) en FastAPI"},"content":{"rendered":"\n<p><strong>Test FastAPI:<\/strong><\/p>\n\n\n\n<p>FastAPI genereert automatisch een interactieve API-documentatie met <strong>Swagger UI<\/strong>:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Start je applicatie:bashCode kopi\u00ebren<code>uvicorn main:app --reload<\/code><\/li>\n\n\n\n<li>Open <a>http:\/\/127.0.0.1:8000\/docs<\/a> in je browser.<\/li>\n\n\n\n<li>Test je endpoints rechtstreeks vanuit de Swagger UI.<\/li>\n<\/ol>\n\n\n\n<p>Of:<\/p>\n\n\n\n<p>pip install pytest httpx<\/p>\n\n\n\n<p>pytest test_main.py<\/p>\n\n\n\n<p>(maak test_main.py:)<\/p>\n\n\n\n<p>from fastapi.testclient import TestClient<br>from main import app<\/p>\n\n\n\n<p>client = TestClient(app)<\/p>\n\n\n\n<p>def test_root():<br>response = client.get(&#8220;\/&#8221;)<br>assert response.status_code == 200<br>assert response.json() == {<br>&#8220;greeting&#8221;: &#8220;Hello, World!&#8221;,<br>&#8220;message&#8221;: &#8220;Welcome to FastAPI!&#8221;<br>}<\/p>\n\n\n\n<p>def test_db():<br>response = client.get(&#8220;\/test-db&#8221;)<br>assert response.status_code == 200<br>assert &#8220;database_url&#8221; in response.json() or &#8220;error&#8221; in response.json()<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Test FastAPI: FastAPI genereert automatisch een interactieve API-documentatie met Swagger UI: Of: pip install pytest httpx pytest test_main.py (maak test_main.py:) from fastapi.testclient import TestClientfrom main import app client = TestClient(app) def test_root():response = client.get(&#8220;\/&#8221;)assert response.status_code == 200assert response.json() == {&#8220;greeting&#8221;: &#8220;Hello, World!&#8221;,&#8220;message&#8221;: &#8220;Welcome to FastAPI!&#8221;} def test_db():response = client.get(&#8220;\/test-db&#8221;)assert response.status_code == 200assert &#8220;database_url&#8221; in response.json() [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"template":"","blossom_portfolio_categories":[30],"class_list":["post-4455","blossom-portfolio","type-blossom-portfolio","status-publish","hentry","blossom_portfolio_categories-ckba"],"_links":{"self":[{"href":"https:\/\/yininit.nl\/index.php\/wp-json\/wp\/v2\/blossom-portfolio\/4455","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/yininit.nl\/index.php\/wp-json\/wp\/v2\/blossom-portfolio"}],"about":[{"href":"https:\/\/yininit.nl\/index.php\/wp-json\/wp\/v2\/types\/blossom-portfolio"}],"author":[{"embeddable":true,"href":"https:\/\/yininit.nl\/index.php\/wp-json\/wp\/v2\/users\/1"}],"wp:attachment":[{"href":"https:\/\/yininit.nl\/index.php\/wp-json\/wp\/v2\/media?parent=4455"}],"wp:term":[{"taxonomy":"blossom_portfolio_categories","embeddable":true,"href":"https:\/\/yininit.nl\/index.php\/wp-json\/wp\/v2\/blossom_portfolio_categories?post=4455"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}