Skip to content

Get Helpers

Naofumi Kagami edited this page Sep 12, 2022 · 2 revisions

API request handling

We provide functions to simplify sending API requests and error handling. Again, since the main objective of this project is initially replicate Rails ERB functionality, we do not provide caching or retry capabilities to compensate for network inefficiencies. Indeed, these features may be less essential since the API requests inside getServerSideProps() will go through inter-data centre networks that are fast and highly reliable, potentially making retries and caching unnecessary.

apiGetProps()

Below is an example of typical usage inside getServerSideProps()

export async function getServerSideProps (context) {
  return apiGetProps({
    context: context,
    url: 'http://web:3000/api/categories',
    options: {},
    success: (response, categories) => {
      return {
        props: {
          categories,
          breadcrumbs: [{name: 'Categories', href: '/'}],
          actionButton: {url: "/categories/new", text: "New Category"}
        }
      }
    }
  })
}

Inside the success callback, you specify the props to send to the page component.

Clone this wiki locally