VirtusLab-Open-Source / strapi-plugin-navigation

A plugin for Strapi Headless CMS that provides navigation / menu builder feature with their possibility to control the audience and different output structure renderers like (flat, tree and RFR - ready for handling by Redux First Router)
MIT License
318 stars 58 forks source link

Typescript Types for REST API Response in Client code #352

Closed EsGeh closed 11 months ago

EsGeh commented 1 year ago

Question

Is there a npm package that provides the necessary type definitions for the client side?

To be more precise: When requesting the api at /api/navigation/render/main-navigation in some client - what typescript type does the returned data have?

Example

Some client trying to fetch navigation data from a strapi backend via REST:

export async function getNavigation()
    // : ???
{
  const response = await fetch( "/api/navigation/render/main-navigation", {} );
  if( ! response?.ok ) {
    throw new Error( `Error when fetching data from '${url}': returned HTTP status '${response.status}'` );
  }
  const data = await response.json();
  if( !data ) {
    throw new Error( `Error when fetching data from '${url}': no data!` );
  }
  return data // as ???
}
cyp3rius commented 1 year ago

Hello @EsGeh ,

there is no such type yet but good shout! I'm putting this request to backlog.

cyp3rius commented 11 months ago

Added in v2.3.1