Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

251
Vistas
What is the best practice to create a GET request with many parameters

Our backend developer implemented an endpoint that allows GET method to get a list of Assets of the database. To filter the Assets that I want in the response, I need to pass some parameters in the URL.

First I implemented the following function to mount the GET request with all available parameters:

fetchAssetList(data) {
    let request_url = 'asset-mgt/assets?'
    if (data.name !== '' && data.name !== null){
      request_url = request_url + "Name=" + data.name + "&"
    }
    if (data.assetCode !== '' && data.assetCode !== null){
      request_url = request_url + "AssetCode=" + data.assetCode + "&"
    }
    if (data.parentAssetName !== '' && data.parentAssetName !== null){
      request_url = request_url + "ParentAssetName=" + data.parentAssetName + "&"
    }
    if (data.type !== -1 && data.type !== null && data.type !== undefined){
      request_url = request_url + "Type=" + data.type + "&"
    }
    if (data.parentAssetId !== -1 && data.parentAssetId !== null && data.parentAssetId !== undefined){
      request_url = request_url + "ParentAssetId=" + data.parentAssetId + "&"
    }
    
    return axiosPrivate.get(request_url);
  },

I am not really happy with the current solution we implemented. The GET request with such many query parameters does not feel right.

Do you think it would be better to have one GET Method which always returns all assets (.../assets), other GET method which takes the id of the asset (.../assets/{id}) and one POST method, which takes a payload to filter (.../assets/filter). What is the best practice?

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda