Code Monkey home page Code Monkey logo

payload-rest-client's People

Contributors

dkirchhof avatar madaxen86 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

payload-rest-client's Issues

Can `qs` be removed so no dependencies?

Great library here!

Quick question - could qs be removed and just use URLSearchParams?

I ask because the qs library is actually kindof big (like 10kb bundled / gzipped) for things like Edge and Cloudflare Workers where performance actually is impacted a lot by bundle size ... also not to mention client-size browser use as well ...

Can Collection/Global be inferred?

Again, huge fan of this library ... the one thing that annoys me though is I would really like to do api.post.find({}) instead of api.collections.post.find({}) ...

maybe this could be managed by following the Payload local API syntax with findGlobal and updateGlobal which is how you could infer the base path.

What do you think? I know it's a breaking change, but it doesn't look like you have a ton of users yet ... although that is likely going to change shortly ...

Narrow Relationships

Example as reference what payload generates

type User = {
   id:string;
   email:string;
   ...
}
type Post = {
   id:string;
   author: {
      relationTo:string;
      value: string | User;
}

When getting posts we also receive the relation author as string | User.
But it actually will only be string if we pass fetchParam
{depth:0}.
I'm not a typescript expert.
Shouldn't it be possible to narrow the relationship types based on the passed parameter for the collections find, findById and for the globals get functions?

Example for Authentication

Hello,

it took some time for me to get the authentication part up and running. maybe we can share something like this in the README.md?

a .env for the credentials (because I like to use dotenv :)):

PAYLOAD_API_URL=http://localhost:3000/api
PAYLOAD_API_EMAIL=
PAYLOAD_API_PASSWORD=

client.js for wrapping the creation:

import { createClient } from "payload-rest-client";


export default async () => {
    let loginClient = await createClient({
        apiUrl: process.env.PAYLOAD_API_URL,
        cache: "no-store"
    });
    let loginResponse = await loginClient.collections.users.login({
        email: process.env.PAYLOAD_API_EMAIL,
        password: process.env.PAYLOAD_API_PASSWORD
    });

    return createClient({
        apiUrl: process.env.PAYLOAD_API_URL,
        cache: "no-store",
        debug: true,
        headers: {
            'Authorization': 'Bearer ' + loginResponse.token
        }
    })
};

and the using part of code:

import 'dotenv/config'
import clientCreator from './client.js';

(async () => {
    let client = await clientCreator();
    let speakers = await client.collections.speakers.find({
        sort: "name",
        locale: "de",
        limit: 10,
        page: 1,
    });
    console.log('speakers', speakers);
})();

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.