# Mocking unfinished endpoints

To build against an endpoint the backend has not finished, mock it in the endpoint definition. When the endpoint is
ready, your components do not change.

```typescript title="resources/Rating"
import { Entity, resource } from '@data-client/rest';
import { Temporal } from 'temporal-polyfill';

export class Rating extends Entity {
  id = '';
  rating = 4.6;
  author = '';
  date = Temporal.Instant.fromEpochMilliseconds(0);

  static key = 'Rating';

  static schema = {
    date: Temporal.Instant.from,
  };
}

export const RatingResource = resource({
  path: '/ratings/:id',
  schema: Rating,
}).extend({
  getList: {
    dataExpiryLength: Infinity,
    fetch() {
      return Promise.resolve(
        ['Morningstar', 'Seekingalpha', 'Morningstar', 'CNBC'].map(author => ({
          id: `${Math.random()}`,
          rating: (2 + Math.random() * 3).toFixed(1),
          author,
          date: '1990-01-01T00:00:00Z',
        })),
      );
    },
  },
});
```

```tsx title="Demo"
import { useSuspense } from '@data-client/react';
import { RatingResource } from './resources/Rating';

function Demo() {
  const ratings = useSuspense(RatingResource.getList);
  return (
    <div>
      {ratings.map(rating => (
        <div key={rating.pk()}>
          {rating.author}: {rating.rating}{' '}
          <time>
            {rating.date.toLocaleString('en-US', { dateStyle: 'medium' })}
          </time>
        </div>
      ))}
    </div>
  );
}
render(<Demo />);
```

The `fetch` override on the [RestEndpoint](https://dataclient.io/rest/api/RestEndpoint.md) returns fake data. The rest of the code uses the
typed `RatingResource` as usual.

When the API is ready, remove the whole `getList` override. Both `fetch` and `dataExpiryLength` exist only for the mock.

`dataExpiryLength: Infinity` stops the data from [expiring](https://dataclient.io/docs/concepts/expiry-policy.md), so Data Client does not refetch it on its own and replace the random values.
