Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetch a Post Resource by default for a new record #307

Closed
jitendrajp opened this issue Mar 10, 2025 · 1 comment
Closed

Fetch a Post Resource by default for a new record #307

jitendrajp opened this issue Mar 10, 2025 · 1 comment

Comments

@jitendrajp
Copy link

The specification states that we able to fetch records using the TYPE and ID. Together, these two things uniquely identify the record in our API. The URL we are following:

 GET: <HOST>/<API_NAMESPACE>/<TYPE>/<ID>

It's fine because the record exists in the table, and it's can loaded with defined fields in the schema.

public function fields(): array
{
    return [
        ID::make(),
        Str::make('name')->sortable(),
        Str::make('email')->sortable(),
        Str::make('phone')->sortable(),
        ...
   ]
}

I want to load these fields when fetching resources with default value for the new record. Maybe something like the URL could be below. new is the static value:

 GET: <HOST>/<API_NAMESPACE>/<TYPE>/new

Response could be like:

 {
     "jsonapi": {
         "version": "1.0"
     },
     "links": {
         "self": "http:\/\/localhost:8000\/api\/v1\/users\/new"
     },
     "data": {
         "type" : "users",
         "attributes" : {
             "name"   : null,
             "email"  : null,
             "phone"  : null,
             ...
         }
     }
}

So, We can keep the single-way attribute handling on both new and existing records. We just use attributes from the server side. Right now, we need to define statically attributes for the new record resource and for the existing record we can use directly from these fields.

@lindyhopchris
Copy link
Contributor

Hi. The purpose of this package is to implement the specification. What you are proposing is not in the specification, therefore cannot be added by this package.

You can of course implement this yourself, and if you want to make it available to others, then you could publish it as a package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants