Sunday, January 28, 2024

Data Seeding

El "Data Seeding" es el  proceso de proporcionar datos iniciales o de muestra a una base de datos cuando esta se crea por primera vez o cuando se aplican migraciones para actualizar su esquema.

Este proceso es especialmente útil en situaciones donde necesitas que la base de datos tenga datos predeterminados para que la aplicación funcione correctamente desde el principio. También es útil para proporcionar datos de muestra en un entorno de desarrollo o para realizar pruebas.

Al realizar "Data Seeding" en Entity Framework Core, generalmente se utiliza el método HasData en el método OnModelCreating de la clase que hereda de DbContext. Este método se utiliza para especificar los datos que se deben insertar en la base de datos durante la creación o actualización de la misma.


Wednesday, January 3, 2024

Designing RESTful Web APIs

Source: https://app.pluralsight.com/library/courses/designing-restful-web-apis/table-of-contents

I. Intro

  • Fundamentals of HTTP and REST
  • Designing the entire API
  • Why versioning is so important
  • Different security considerations

II. What is REST?

The history of distributed APIs

HTTP
How does HTTP work?


The request deconstructed





The response deconstructed





REST

What is REST?
 - REpresentational State Transfer
- Separation of Client and Server
- Server Requests are Stateless
- Cacheable Requests
- Uniform Interface

III. Designing a RESTful API

Intro
  • Designing the API First
  • Nouns and Verbs
  • URI Design
  • Status Codes
  • Designing Results

Design your API first


¿Por qué?
  • Can't fix an API after publishing
  • Too easy to add ad-hoc endpoints
  • Helps understand the requirements
  • Well-designed API can mature
REST APIs have several parts

What are URIs? 
  • URIs are just paths to resources. 
  • Example: api.yourserver.com/people

API Design
  • Nouns are good, and verbs are bad.



What are "resources"?
  • Collections of nouns


  • Complex objects

Identifiers in URIs
  • Use unique identifiers
  • Does not have to be "primary keys"

Query Strings
  • Use for non-resource properties
  • Format, sorting, searching, etc. 

Design Verbs
  • GET: Retrieve a resource
  • POST: Add a new resource
  • PUT: Update an existing resource
  • PATCH: Update a resource with changes
  • DELETE: Remove the existing resource

Idempotency in Action
  • Operation that can be applied multiple times without changing the result
  • Operations result in same side effect
    • GET, PUT, PATCH and DELETE
  • POST is not idempotent

Designing Results
  • Members Names
    • Shouldn't expose server details.
    • I prefer camelCasing
  • Designing Collections


Formatting Results




Hypermedia
  • Allows results to be self-describing
  • Allows programatic navigation
  • Adds complexity

  • Hypermedia ca be helpful, but pragmatism means that most projects don't need it.

IV. Handling more complex scenarios in your API

  • abc

Versioning your API

  • abc

Locking down your API

  • abc


API Gateway with ASP.NET Core

Grandes preguntas: ¿Repites mucho código en cada nuevo microservicio? ¿Haces que tus frontends llamen múltiples endpoints para obtener lo qu...