Introducción a JavaScript
¿Por qué aprender JavaScript?
¡Hola Mundo! en Mac
¡Hola Mundo! en Windows
Anatomía de una variable
Tipos de datos en JavaScript
Creación de strings
Operadores aritméticos
Conversión de tipos: Type Casting y Coerción
Conversión de tipos explícita e implícita
Estructuras de Control y Lógica
Operadores de comparación
Operadores lógicos
Ejecución condicional: if
Ejercicio: Adivina el número
Ejecución condicional: switch
Loop: for
Loop: for of
Loop: for in
Loop: while
Loop: do while
Funciones y This
Anatomía de una función
Funciones vs Métodos
Funciones puras e impuras
Arrow function y enlace léxico
Contextos de ejecución y scope chain
¿Qué es Closure?
Preguntas a Desarrolladores Senior: ¿Por qué aprender Desarrollo Web?
Manipulación de Arrays
Introducción a Arrays
Mutabilidad e inmutabilidad de Arrays
Modificación básica del final con push( ), pop( )
Iteración con map( ) y forEach( )
Filtrado y reducción con filter( ) y reduce( )
Búsqueda de elementos con find( ) y findIndex( )
Crear copias con slice( )
Spread operator: casos de uso
Programación Orientada a Objetos
Anatomía de un Objeto
Trabajando con objetos en JavaScript
Función constructora
¿Qué es una clase?
Prototipos y herencias
Herencia en la práctica
Prototipos en la práctica
this en JavaScript
Proyecto: Crea una red social
Proyecto: Crea una red social parte 2
Asincronía en JavaScript
¿Cómo funciona el JavaScript Engine?
Promesas en JavaScript
Usando Async y await en JavaScript
For await of
¿Cómo funciona la web?
¿Cómo funciona HTTP?
Método GET en JavaScript
Método POST en JavaScript
Método DELETE en JavaScript
Importancia del id en el método DELETE
ECMAScript 6 y tus siguientes pasos
You don't have access to this class
Keep learning! Join and start boosting your career
When developing web applications, understanding how to handle HTTP requests is fundamental for communication between the front-end and the servers. HTTP (Hypertext Transfer Protocol) is the protocol for making data requests and sending information between clients and servers. In practice, HTTP methods are used using the fetch
function in JavaScript to interact with APIs.
fetch
requests work?When we use fetch
, we are requesting a server to provide us with information that we can then handle and display in the DOM. Using fetch
, we make a request to an API, which often returns data in JSON format. Using fetch
is a way to make HTTP requests asynchronously, which allows us to improve the user experience by loading data without interrupting the flow of the application.
fetch('https://jsonplaceholder.typicode.com/posts').then(response => response.json()).then(data => console.log(data));
This code performs a GET request to an example API that returns dummy information.
When making HTTP requests, it is crucial to interpret the status codes that accompany them, since they tell us the result of the requested operation:
Knowing these codes helps us to diagnose problems and understand the communication between the client and the server.
The browser offers development tools that facilitate the monitoring of HTTP requests. The "Network" tab allows us to observe:
By accessing the "Network" tab, we can determine the success of our requests and understand what happens with each request that is made, strengthening our knowledge of data management in web applications.
Let's imagine that we are generating information from an API using fetch
. We can drill down and work with the returned information to, for example, obtain user details and display them in our application.
When fetch
is executed, the API is queried and, using promises(then
), we handle the response. If the request is successful, we get a JSON object with the data:
fetch('https://jsonplaceholder.typicode.com/posts').then(response => response.json()).then(data => { // Data is processed to display titles, users, etc. data.forEach(post => { console.log(post.title); }); });
This basic structure demonstrates how we can extend the functionality of fetch
to suit the needs of our application.
Understanding HTTP and fetch
gives us control over the front-end interactions with the server, allowing us to optimize the development process and providing a more efficient and dynamic user experience. Keep exploring and experimenting with different scenarios to expand your skills!
Contributions 7
Questions 0
Want to see more contributions, questions and answers from the community?