Skip to content

Latest commit

 

History

13 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Módulo de Clientes (Go)

Proyecto de ejemplo para el Hito 2: módulo CRUD de clientes en Go.

Estructura

  • cmd/api/main.go — entrada principal del servidor
  • internal/models/ — definición del struct Client
  • internal/handlers/ — handlers HTTP
  • internal/storage/ — almacenamiento en memoria

Endpoints

Base: http://localhost:8080/api/v1/clientes

  • GET / — lista todos los clientes (200)
  • POST / — crea cliente (201)
  • GET /{id} — obtiene cliente por id (200 / 404)
  • PUT /{id} — actualiza cliente (200 / 404 / 400)
  • DELETE /{id} — elimina cliente (204 / 404)

Validación

  • nombre es obligatorio en POST y PUT
  • JSON inválido responde 400
  • Id no encontrado responde 404

Ejecutar

cd "C:\Users\AlexGC\OneDrive\Escritorio\Modulo de clientes"
go mod tidy
go run ./cmd/api

Ejemplos de curl

Crear cliente:

curl -X POST http://localhost:8080/api/v1/clientes/ \
  -H "Content-Type: application/json" \
  -d '{"nombre":"Juan Pérez","correo":"juan@example.com","telefono":"1234567890","direccion":"Calle Falsa 123","rfc":"JUAP800101"}'

Listar clientes:

curl http://localhost:8080/api/v1/clientes/

Obtener cliente por ID:

curl http://localhost:8080/api/v1/clientes/1

Actualizar cliente:

curl -X PUT http://localhost:8080/api/v1/clientes/1 \
  -H "Content-Type: application/json" \
  -d '{"nombre":"Juan Pérez","correo":"juan.nuevo@example.com","telefono":"1234567890","direccion":"Calle Falsa 123","rfc":"JUAP800101"}'

Eliminar cliente:

curl -X DELETE http://localhost:8080/api/v1/clientes/1

Checklist para el Hito 2

  • cmd/api/main.go con router Chi y subrouter /api/v1
  • internal/models/ con struct Client y tags JSON
  • internal/handlers/ con los 5 handlers CRUD
  • internal/storage/ con almacenamiento en memoria
  • Validación básica de nombre obligatorio
  • Status codes correctos: 200, 201, 404, 400, 204
  • DOCUMENTO_TECNICO.md añadido
  • curl_commands.sh con ejemplos de demo
  • .gitignore para archivos binarios y temporales

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages