<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Backend and FastAPI on kodkod | Intro Course</title><link>https://intro-kodkod-6.nm-ambition.com/en/docs/backend-fastapi/</link><description>Recent content in Backend and FastAPI on kodkod | Intro Course</description><generator>Hugo</generator><language>en</language><copyright>מבואות קודקוד</copyright><atom:link href="https://intro-kodkod-6.nm-ambition.com/en/docs/backend-fastapi/index.xml" rel="self" type="application/rss+xml"/><item><title>Backend and HTTP: Who Does What, Methods and Status Codes</title><link>https://intro-kodkod-6.nm-ambition.com/en/docs/backend-fastapi/01-what-is-backend/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://intro-kodkod-6.nm-ambition.com/en/docs/backend-fastapi/01-what-is-backend/</guid><description>&lt;h2 id="in-this-lesson"&gt;In this lesson&lt;/h2&gt;
&lt;p&gt;This lesson is built from two chapters, in the same order as the slides:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Chapter 1&lt;/strong&gt; — what a Backend is: Client, Server, Database, API and Endpoint&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Chapter 2&lt;/strong&gt; — HTTP Methods and Status Codes&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id="chapter-1-what-a-backend-is--client-server-database-api-and-endpoint"&gt;Chapter 1: What a Backend Is — Client, Server, Database, API and Endpoint&lt;/h2&gt;
&lt;h3 id="what-will-we-learn"&gt;What will we learn?&lt;/h3&gt;
&lt;p&gt;Now we move from programs that run &lt;strong&gt;on our own computer&lt;/strong&gt; to software that &lt;strong&gt;others&lt;/strong&gt; talk to over the network. This lesson gives the big picture and the words:&lt;/p&gt;</description></item><item><title>FastAPI from Scratch: Installation, app = FastAPI(), a First Route and Running the Server</title><link>https://intro-kodkod-6.nm-ambition.com/en/docs/backend-fastapi/04-fastapi-setup-first-route/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://intro-kodkod-6.nm-ambition.com/en/docs/backend-fastapi/04-fastapi-setup-first-route/</guid><description>&lt;h2 id="what-will-we-learn"&gt;What will we learn?&lt;/h2&gt;
&lt;p&gt;This lesson is a &lt;strong&gt;full setup, from scratch&lt;/strong&gt;, of a real server:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;A virtual environment&lt;/strong&gt; (venv): where libraries are installed.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Installing FastAPI&lt;/strong&gt; with &lt;code&gt;pip&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;main.py&lt;/code&gt;&lt;/strong&gt;: importing, creating &lt;code&gt;app&lt;/code&gt;, and a first &lt;strong&gt;Route&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Running&lt;/strong&gt; it with &lt;code&gt;uvicorn&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Testing&lt;/strong&gt;: the browser, curl, and the automatic documentation page &lt;code&gt;/docs&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id="why-do-we-need-this"&gt;Why do we need this?&lt;/h2&gt;
&lt;p&gt;In the networking topic we saw what a &amp;ldquo;manual&amp;rdquo; server involves: &lt;code&gt;bind&lt;/code&gt;, &lt;code&gt;listen&lt;/code&gt;, &lt;code&gt;accept&lt;/code&gt;, and decoding text. That is a lot of work, and it is easy to crash on bad input. &lt;strong&gt;FastAPI&lt;/strong&gt; does all of this for us: it receives the request, decodes HTTP, finds the right function, converts the response to JSON, and checks types. We write &lt;strong&gt;only the logic&lt;/strong&gt;.&lt;/p&gt;</description></item><item><title>Path Params, Query Parameters and Body</title><link>https://intro-kodkod-6.nm-ambition.com/en/docs/backend-fastapi/03-params-query-body/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://intro-kodkod-6.nm-ambition.com/en/docs/backend-fastapi/03-params-query-body/</guid><description>&lt;h2 id="what-will-we-learn"&gt;What will we learn?&lt;/h2&gt;
&lt;p&gt;A Client needs to tell the server &lt;strong&gt;what&lt;/strong&gt; exactly it wants. It has three ways:&lt;/p&gt;
&lt;table&gt;
 &lt;thead&gt;
 &lt;tr&gt;
 &lt;th&gt;Way&lt;/th&gt;
 &lt;th&gt;Where&lt;/th&gt;
 &lt;th&gt;Example&lt;/th&gt;
 &lt;/tr&gt;
 &lt;/thead&gt;
 &lt;tbody&gt;
 &lt;tr&gt;
 &lt;td&gt;&lt;strong&gt;Path Parameter&lt;/strong&gt;&lt;/td&gt;
 &lt;td&gt;Part of the path itself&lt;/td&gt;
 &lt;td&gt;&lt;code&gt;/students/7&lt;/code&gt;&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;&lt;strong&gt;Query Parameters&lt;/strong&gt;&lt;/td&gt;
 &lt;td&gt;After &lt;code&gt;?&lt;/code&gt; in the URL&lt;/td&gt;
 &lt;td&gt;&lt;code&gt;/students?city=Haifa&amp;amp;limit=10&lt;/code&gt;&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;&lt;strong&gt;Body&lt;/strong&gt;&lt;/td&gt;
 &lt;td&gt;In the body of the request (JSON)&lt;/td&gt;
 &lt;td&gt;&lt;code&gt;{&amp;quot;name&amp;quot;: &amp;quot;Dana&amp;quot;, &amp;quot;age&amp;quot;: 24}&lt;/code&gt;&lt;/td&gt;
 &lt;/tr&gt;
 &lt;/tbody&gt;
&lt;/table&gt;
&lt;h2 id="why-do-we-need-this"&gt;Why do we need this?&lt;/h2&gt;
&lt;p&gt;In the next lesson we will write the first server, and in FastAPI each of the three is defined in a different way. If you don&amp;rsquo;t understand the difference, you put information in the wrong place: an identifier in the Body, or a password in the URL. And every real API you will consume (GitHub, weather, payments) uses all three.&lt;/p&gt;</description></item><item><title>FastAPI: Path Params, Query, Body and HTTPException</title><link>https://intro-kodkod-6.nm-ambition.com/en/docs/backend-fastapi/05-fastapi-params-query-body/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://intro-kodkod-6.nm-ambition.com/en/docs/backend-fastapi/05-fastapi-params-query-body/</guid><description>&lt;h2 id="what-will-we-learn"&gt;What will we learn?&lt;/h2&gt;
&lt;p&gt;In the previous lesson the functions received no input at all. Now they will receive the three kinds we learned:&lt;/p&gt;</description></item><item><title>Middleware: Code That Runs on Every Request</title><link>https://intro-kodkod-6.nm-ambition.com/en/docs/backend-fastapi/06-middleware/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://intro-kodkod-6.nm-ambition.com/en/docs/backend-fastapi/06-middleware/</guid><description>&lt;h2 id="what-will-we-learn"&gt;What will we learn?&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Which problem there is when you want to do something on &lt;strong&gt;every&lt;/strong&gt; request.&lt;/li&gt;
&lt;li&gt;What &lt;strong&gt;Middleware&lt;/strong&gt; is, and how it is related to the &lt;strong&gt;Decorator&lt;/strong&gt; we already know.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;@app.middleware(&amp;quot;http&amp;quot;)&lt;/code&gt;&lt;/strong&gt;, &lt;strong&gt;&lt;code&gt;call_next&lt;/code&gt;&lt;/strong&gt;, &lt;strong&gt;&lt;code&gt;async&lt;/code&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;code&gt;await&lt;/code&gt;&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;A &lt;strong&gt;log&lt;/strong&gt; and &lt;strong&gt;time measurement&lt;/strong&gt; for every request in the students API, and a &lt;strong&gt;Header&lt;/strong&gt; that is added to every response.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="why-do-we-need-this"&gt;Why do we need this?&lt;/h2&gt;
&lt;p&gt;The students API from the previous lesson works. Now we want to know &lt;strong&gt;what happens in it&lt;/strong&gt;: which request arrived, which code came back, and how long it took. The first way that comes to mind — add a log line to every Route:&lt;/p&gt;</description></item></channel></rss>