No tienes acceso a esta clase

隆Contin煤a aprendiendo! 脷nete y comienza a potenciar tu carrera

Curso Profesional de Next.js

Curso Profesional de Next.js

Oscar Barajas Tavares

Oscar Barajas Tavares

Presentaci贸n de la API

10/31
Recursos

Aportes 4

Preguntas 3

Ordenar por:

Los aportes, preguntas y respuestas son vitales para aprender en comunidad. Reg铆strate o inicia sesi贸n para participar.

Todos los endpoints que hab铆an en el swager a la fecha, por si desean tomarlos, recuerden siempre revisar que no haya un typo o algo por el estilo.

const API = process.env.NEXT_PUBLIC_API_URL;
const VERSION = process.env.NEXT_PUBLIC_API_VERSION;

const endPoints = {
  products:{
    getProducts: `${API}/api/${VERSION}/products/`,
    postProducts: `${API}/api/${VERSION}/products/`,
    getProduct: (id) => `${API}/api/${VERSION}/products/${id}`,
    putProducts: (id) => `${API}/api/${VERSION}/products/${id}`,
    deleteProducts: (id) => `${API}/api/${VERSION}/products/${id}`
  },
  users:{
    getUsers: `${API}/api/${VERSION}/users`,
    postUsers: `${API}/api/${VERSION}/users`,
  },  
  auth: {
    login: `${API}/api/${VERSION}/auth/login`,
    profile: `${API}/api/${VERSION}/auth/profile`
  },
  categories:{
    getCategories: `${API}/api/${VERSION}/categories`,
    postCategories: `${API}/api/${VERSION}/categories`,
    getCategoriesProduct: (id) => `${API}/api/${VERSION}/categories/${id}/products`,
    putCategories: (id) => `${API}/api/${VERSION}/categories/${id}`,
  },
  files:{
    postFiles: `${API}/api/${VERSION}/files/upload`,
    getFiles: (fileName) => `${API}/api/${VERSION}/${fileName}`
  }
  
}

export default endPoints

Esta clase me parece re importante por la forma en gestionar y segementar los endpoints desde el frontend

// admin the requests the endpoints
const API = process.env.NEXT_PUBLIC_API_URL;
const VERSION = process.env.NEXT_PUBLIC_API_URL_VERSION;

const endpoints = {
  auth: {
    login: `${API}/api/${VERSION}/auth/login`,
    profile: `${API}/api/${VERSION}/auth/profile`,
  },
  products: {
    getAllProducts: `${API}/api/${VERSION}/products`,
    getProduct: (id) => `${API}/api/${VERSION}/products/${id}`,
  },
  users: {
    getAllUsers: `${API}/api/${VERSION}/users`,
    userIsAvailable: `${API}/api/${VERSION}/users/is-available`,
  },
  categories: {
    getAllCategories: `${API}/api/${VERSION}/categories`,
    getCategory: (id) => `${API}/api/${VERSION}/categories/${id}`,
    getCategoryWithProduct: (id) => `${API}/api/${VERSION}/categories/${id}/products`,
  },
  files: {
    upload: `${API}/api/${VERSION}/files/upload`,
    getFile: (fileName) => `${API}/api/${VERSION}/files/${fileName}`,
  },
};

export default endpoints;

El reto de la clase:

const API = process.env.NEXT_PUBLIC_API_URL;
const VERSION = process.env.NEXT_PUBLIC_API_VERSION;

const endpoints = {
    auth: {
        login: `${API}/${VERSION}/auth/login`,
        profile: `${API}/${VERSION}/auth/profile`,
    },
    categories: {
        list: `${API}/${VERSION}/categories`,
        create: `${API}/${VERSION}/categories`,
        get: (id) => `${API}/${VERSION}/categories/${id}`,
        update: (id) => `${API}/${VERSION}/categories/${id}`,
        categoryProducts: (id) => `${API}/${VERSION}/categories/${id}/products`,
    },
    files: {
        upload: `${API}/${VERSION}/files/upload`,
        get: (filename) => `${API}/${VERSION}/files/${filename}`,
    },
    products: {
        list: `${API}/${VERSION}/products`,
        paginate: (limit = 10, offset = 1) => `${API}/${VERSION}/products?limit=${limit}&offset=${offset}`,
        get: (id) => `${API}/${VERSION}/products/${id}`,
        create: `${API}/${VERSION}/products`,
        update: (id) => `${API}/${VERSION}/products/${id}`,
        delete: (id) => `${API}/${VERSION}/products/${id}`,
    },
    users: {
        list: `${API}/${VERSION}/users`,
        create: `${API}/${VERSION}/users`,
        isAvailable: `${API}/${VERSION}/users/is-available/`,
    },
};

export default endpoints;

La actividad del final de clase:

const API = process.env.NEXT_PUBLIC_API_URL
const API_VERSION = process.env.NEXT_PUBLIC_API_VERSION

const endPoints = {
  auth: {
    login: `${API}/${API_VERSION}/auth/login`,
    profile: `${API}/${API_VERSION}/auth/profile`,
  },
  products: {
    products: (limit = 10, offset = 0) => `${API}/${API_VERSION}/products?limit=${limit}&offset=${offset}`,
    product: id => `${API}/${API_VERSION}/products/${id}`,
  },
  users: {
    users: `${API}/${API_VERSION}/users`,
    isAvailable: `${API}/${API_VERSION}/users/is-available`,
  },
  categories: {
    categories: `${API}/${API_VERSION}/categories`,
    category: id => `${API}/${API_VERSION}/categories/${id}`,
  },
  files: {
    uploadFile: `${API}/${API_VERSION}/files/upload`,
    file: fileName => `${API}/${API_VERSION}/files/${fileName}`,
  }
}