neiist-dev/neiist-website

API Service File

Closed this issue · 0 comments

We should have a specific file with all API calls we do, to maintain the code readability and maintainability.

Example:
From

fetch(`/api/members/${userData.username}`)
      .then((res) => res.json())
      .then((fetchMember) => {
          setMember(fetchMember);
          setIsLoaded(true);
        },
        (err) => {
          setIsLoaded(true);
          setError(err);
        },
      );

To

APIService.fetchMember(username)
      .then(fetchMember) => {
          setMember(fetchMember);
          setIsLoaded(true);
        },
        (err) => {
          setIsLoaded(true);
          setError(err);
        },
      );