Relying on onClick for API calls often breaks form behavior. Learn why Fetch handles errors differently than Axios and how to manage status codes.

Controlled components are what separate professional apps from amateur ones because they allow for real-time feedback. React should be the single source of truth, creating a perfect loop between the state and the user's input.
Backend - API Development: API fundamentalsYour first API endpointHTML formsHTML inputsReact controlled formsAPI callsAxios (HTTP client)HTTP status codesError handling & messagesOptional chaining operator


Using "onSubmit" on the HTML form element allows you to tap into the web’s natural behavior, such as triggering a submission when a user hits the "Enter" key. It also enables automatic browser validation features. When using this method, it is essential to call "event.preventDefault()" to stop the page from reloading, which would otherwise cause the application to lose its current state.
A major misconception is that Fetch and Axios handle server errors the same way. Fetch only rejects a promise if there is a network failure; it actually considers HTTP 500 server crashes or 404 errors as "successful" resolutions. Axios, however, is designed to automatically treat any status code outside the 2xx range as an error, allowing developers to catch server-side issues directly within a "catch" block.
Controlled components are form elements where React acts as the "single source of truth" for the input's value. Instead of the browser's DOM holding the text, the value is tied to a specific piece of React state, and an "onChange" handler updates that state with every keystroke. This approach is preferred because it allows for real-time feedback, such as instant field validation, password strength meters, or automatic phone number formatting.
When a request fails backend validation, FastAPI returns an HTTP 422 Unprocessable Entity error. The response body contains a "detail" array that specifies the exact location of the error, such as a specific field name, and a message explaining the issue. Developers can map these specific server-side errors back to the React form state to display helpful, inline error messages directly under the relevant input fields.
When an API call begins, developers typically set a "loading" state to true to disable the submit button and prevent duplicate entries. If the loading state is only set to false in the success path, a server error could leave the button disabled forever, trapping the user. Using a "finally" block ensures that the loading state is reset to false regardless of whether the call succeeded or failed, allowing the user to try again.
From Columbia University alumni built in San Francisco
"Instead of endless scrolling, I just hit play on BeFreed. It saves me so much time."
"I never knew where to start with nonfiction—BeFreed’s book lists turned into podcasts gave me a clear path."
"Perfect balance between learning and entertainment. Finished ‘Thinking, Fast and Slow’ on my commute this week."
"Crazy how much I learned while walking the dog. BeFreed = small habits → big gains."
"Reading used to feel like a chore. Now it’s just part of my lifestyle."
"Feels effortless compared to reading. I’ve finished 6 books this month already."
"BeFreed turned my guilty doomscrolling into something that feels productive and inspiring."
"BeFreed turned my commute into learning time. 20-min podcasts are perfect for finishing books I never had time for."
"BeFreed replaced my podcast queue. Imagine Spotify for books — that’s it. 🙌"
"It is great for me to learn something from the book without reading it."
"The themed book list podcasts help me connect ideas across authors—like a guided audio journey."
"Makes me feel smarter every time before going to work"
From Columbia University alumni built in San Francisco
