-
Notifications
You must be signed in to change notification settings - Fork 2k
docs: Created a new Make an RESTful API guide #9808
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
base: 4.7
Are you sure you want to change the base?
Conversation
neznaika0
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Guides are a great idea. We can discuss on the forum what built-in mechanics are possible using the framework. I tried to tell you about the Validator, but you didn't approve.
I looked it up from phone.
|
|
||
| .. code-block:: console | ||
|
|
||
| php spark make:controller Api/Books |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Book or Books? You use a different naming convention below the text.
It is recommended to name endpoints in the plural /books/123
|
|
||
| class BookModel extends Model | ||
| { | ||
| protected string $table = 'books'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Many people recommend naming tables in the singular: book, author
I can't check everything, but could it affect the internal automation? Is there a dependence on the ending "s"?
| This creates a new file under ``app/Database/Migrations/``. | ||
|
|
||
| Edit the CreateAuthorsTable file to look like this: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The file here is ``CreateAuthorsTable.php`` For visual perception.
|
|
||
| Each author simply has a name for our purposes. We have made the name a uncommented unique key to prevent duplicates. | ||
|
|
||
| Now edit the CreateBooksTable file to look like this: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The file here is ``CreateBooksTable.php`` For visual perception.
|
|
||
| The "Improved" auto router is more secure and reliable than the legacy version, so it's recommended for all new projects. | ||
|
|
||
| Then, in ``app/Config/Routing.php`` confirm auto routing is **on**: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On? Maybe "enabled"?
| Getting Started with REST APIs | ||
| ############################## | ||
|
|
||
| .. content:: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo .. contents::
|
You have moved the pages to the directory. Some error correction paths need to be updated. |
Description
This creates a new "Getting Started with RESTful APIs" guide that steps through using the auto-routing and ResponseTrait, plus the new transformers and API response pagination to create a simple API.
It moves the existing tutorial under a new "Guides" section.