https://github.com/jay-es/jsonplaceholder-client
Fully typed client of the JSONPlaceholder API for TypeScript/JavaScript.
https://github.com/jay-es/jsonplaceholder-client
api jsonplaceholder typescript
Last synced: 3 months ago
JSON representation
Fully typed client of the JSONPlaceholder API for TypeScript/JavaScript.
- Host: GitHub
- URL: https://github.com/jay-es/jsonplaceholder-client
- Owner: jay-es
- Created: 2023-05-26T13:18:28.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-11-25T11:02:41.000Z (7 months ago)
- Last Synced: 2025-04-06T06:16:45.707Z (3 months ago)
- Topics: api, jsonplaceholder, typescript
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/@jay-es/jsonplaceholder-client
- Size: 146 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# JSONPlaceholder client




Fully typed client of [the JSONPlaceholder API](https://jsonplaceholder.typicode.com/) for TypeScript/JavaScript.
## Install
```sh
$ npm install @jay-es/jsonplaceholder-client
```## Features
```ts
// 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
```ts
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);
```