1.0.5 • Published 3 years ago

dummy-apis-jsonplaceholder v1.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

dummy-apis-jsonplaceholder

dummy-apis-jsonplaceholder is a collection of dummy api urls based on jsonplaceholder like https://jsonplaceholder.typicode.com/posts.

Quick Start

yarn add dummy-apis-jsonplaceholder
npm i dummy-apis-jsonplaceholder

Examples

import { dummyApiUrl, DummyPost } from "dummy-apis-jsonplaceholder";
const response = await axios.get<DummyPost[]>(dummyApiUrl().posts.index);
const response = await axios.get<DummyPost>(dummyApiUrl(2).posts.index);
// with react
import { MouseEventHandler, useCallback, useState } from "react";
import { dummyApiUrl, DummyPost } from "dummy-apis-jsonplaceholder";
import axios from "axios";

export default function Home(): JSX.Element {
  const [posts, setPosts] = useState<DummyPost[] | null>(null);

  const handleButtonClick: MouseEventHandler<HTMLButtonElement> =
    useCallback(async (): Promise<void> => {
      const response = await axios.get<DummyPost[]>(dummyApiUrl().posts.index);
      setPosts(response.data);
    }, []);

  return (
    <div>
      <button onClick={handleButtonClick}>get api</button>
      {posts?.map((post) => (
        <div key={post.id}> {post.title}</div>
      ))}
    </div>
  );
}
1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago