@jay-es/jsonplaceholder-client
v0.3.0
Published
Fully typed client for JSONPlaceholder
Downloads
7
Readme
JSONPlaceholder client
Fully typed client of the JSONPlaceholder API for TypeScript/JavaScript.
Install
$ npm install @jay-es/jsonplaceholder-client
Features
// Getting a resource
const post = await getPost(1);
// Listing all resources
const allPosts = await getPosts();
// Filtering resources
const user1Posts = await getPosts({ userId: 1 });
// Creating a resource
await createPost({ userId: 7, title: "Foo", body: "Lorem ipsum" });
// Updating a resource
await updatePost(1, { id: 1, userId: 7, title: "Foo", body: "Lorem ipsum" });
// Patching a resource
await patchPost(1, { title: "Foo" });
// Deleting a resource
await deletePost(1);
Resources
| post | comment | album | photo | todo | user |
| :----------: | :-------------: | :-----------: | :-----------: | :----------: | :----------: |
| getPosts
| getComments
| getAlbums
| getPhotos
| getTodos
| getUsers
|
| getPost
| getComment
| getAlbum
| getPhoto
| getTodo
| getUser
|
| createPost
| createComment
| createAlbum
| createPhoto
| createTodo
| createUser
|
| updatePost
| updateComment
| updateAlbum
| updatePhoto
| updateTodo
| updateUser
|
| patchPost
| patchComment
| patchAlbum
| patchPhoto
| patchTodo
| patchUser
|
| deletePost
| deleteComment
| deleteAlbum
| deletePhoto
| deleteTodo
| deleteUser
|
Listing nested resources
e.g. https://jsonplaceholder.typicode.com/posts/1/comments
const comments = await getPostComments(1);
const photos = await getAlbumPhotos(1);
const albums = await getUserAlbums(1);
const todos = await getUserTodos(1);
const posts = await getUserPosts(1);