Skip to content

Commit 87ead0d

Browse files
paulbalandanneznaika0datamweb
committed
Apply suggestions from code review
Co-authored-by: neznaika0 <ozornick.ks@gmail.com> Co-authored-by: Pooya Parsa <pooya_parsa_dadashi@yahoo.com>
1 parent 094e61c commit 87ead0d

File tree

7 files changed

+26
-26
lines changed

7 files changed

+26
-26
lines changed

user_guide_src/source/guides/api/code/013.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
class BookModel extends Model
88
{
9-
protected string $table = 'books';
9+
protected string $table = 'book';
1010
protected array $allowedFields = ['title', 'author_id', 'year'];
1111

1212
/**

user_guide_src/source/guides/api/controller.rst

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Run the Spark command:
2020
2121
php spark make:controller Api/Books
2222
23-
This creates ``app/Controllers/Api/Books.php``.
23+
This creates **app/Controllers/Api/Books.php**.
2424

2525
Open it and replace its contents with the following stubbed out class:
2626

@@ -30,7 +30,7 @@ Since we're using auto-routing, we need to use the ``index`` method names so it
3030

3131
.. tip::
3232

33-
If you prefer a different naming scheme, you would need to define routes explicitly in ``app/Config/Routes.php`` and turn auto-routing off.
33+
If you prefer a different naming scheme, you would need to define routes explicitly in **app/Config/Routes.php** and turn auto-routing off.
3434

3535
API Transformers
3636
=================
@@ -45,7 +45,7 @@ Create the transformers with the generator command:
4545
4646
The transormer requires a single method, ``toArray`` to be present and accept a mixed data type called ``$resource``. This method is responsible for transforming the resource into an array format suitable for API responses. The returned array is what is then encoded as JSON or XML for the API response.
4747

48-
Edit the Book transformer at ``app/Transformers/BookTransformer.php``. This one is a little more complex since it includes related author data:
48+
Edit the Book transformer at **app/Transformers/BookTransformer.php**. This one is a little more complex since it includes related author data:
4949

5050
.. literalinclude:: code/011.php
5151

@@ -133,7 +133,7 @@ If you see JSON data from your seeder, congratulations—your API is live!
133133
Implement the remaining methods
134134
===============================
135135

136-
Edit ``app/Controllers/Api/Book.php`` to include the remaining methods:
136+
Edit **app/Controllers/Api/Book.php** to include the remaining methods:
137137

138138
.. literalinclude:: code/012.php
139139

@@ -142,13 +142,13 @@ Each method uses helpers from :php:trait:`ResponseTrait` to send proper HTTP sta
142142
And that's it! You now have a fully functional RESTful API for managing books, complete with proper HTTP methods, status codes, and data transformation. You can further enhance this API by adding authentication, validation, and other features as needed.
143143

144144
A More Semantic Name scheme
145-
============================
145+
===========================
146146

147147
In the previous examples, we used method names like ``getIndex``, ``putIndex``, etc because we wanted to solely rely on the HTTP verb to determine the action. With auto-routing enabled, we have to use the ``index`` method name to avoid conflicts with URI segments. However, if you prefer more semantic method names, you could change the method names so that they reflect the action being performed, such as ``getList``, ``postCreate``, ``putUpdate``, and ``deleteDelete``. This would then make each method's purpose clearer at a glance. And would just add one new segment to the URI.
148148

149149
```
150-
GET /api/book/list -> getList()
151-
POST /api/book/create -> postCreate()
152-
PUT /api/book/update/(:id) -> putUpdate($id)
153-
DELETE /api/book/delete/(:id) -> deleteDelete($id)
150+
GET /api/books/list -> getList()
151+
POST /api/books/create -> postCreate()
152+
PUT /api/books/update/(:id) -> putUpdate($id)
153+
DELETE /api/books/delete/(:id) -> deleteDelete($id)
154154
```

user_guide_src/source/guides/api/database-setup.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.. _ci47-rest-part3:
22

33
Creating the Database and Model
4-
################################
4+
###############################
55

66
.. contents::
77
:local:
@@ -21,15 +21,15 @@ Run the Spark command:
2121
php spark make:migration CreateAuthorsTable
2222
php spark make:migration CreateBooksTable
2323
24-
This creates a new file under ``app/Database/Migrations/``.
24+
This creates a new file under **app/Database/Migrations/**.
2525

2626
Edit the **CreateAuthorsTable.php** file to look like this:
2727

2828
.. literalinclude:: code/004.php
2929

3030
Each author simply has a name for our purposes. We have made the name a uncommented unique key to prevent duplicates.
3131

32-
Now edit the CreateBooksTable file to look like this:
32+
Now, edit the **CreateBooksTable.php** file to look like this:
3333

3434
.. literalinclude:: code/005.php
3535

@@ -44,7 +44,7 @@ Now run the migration:
4444
Now the database has the necessary structure to hold our books and authors.
4545

4646
Create a seeder
47-
================
47+
===============
4848

4949
Seeders let you load sample data for development so you have something to work with right away. In this case, we’ll create a seeder to add some example books and their authors.
5050

@@ -54,7 +54,7 @@ Run:
5454
5555
php spark make:seeder BookSeeder
5656
57-
Edit the file at ``app/Database/Seeds/BookSeeder.php``:
57+
Edit the file at **app/Database/Seeds/BookSeeder.php**:
5858

5959
.. literalinclude:: code/006.php
6060

user_guide_src/source/guides/api/first-endpoint.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ In this section, we will enable CodeIgniter's *Improved Auto Routing* feature an
1212
Why Auto-Routing?
1313
==================
1414

15-
The previous tutorial introduced you to defined routes manually in ``app/Config/Routes.php``. While this is a powerful and flexible way to define your application's routing, it can be tedious for building RESTful APIs where you may have many endpoints that follow a common pattern. Auto-Routing simplifies this by automatically mapping URL patterns to controller classes and methods based on conventions, and the focus on HTTP verbs works quite well for RESTful APIs.
15+
The previous tutorial introduced you to defined routes manually in **app/Config/Routes.php**. While this is a powerful and flexible way to define your application's routing, it can be tedious for building RESTful APIs where you may have many endpoints that follow a common pattern. Auto-Routing simplifies this by automatically mapping URL patterns to controller classes and methods based on conventions, and the focus on HTTP verbs works quite well for RESTful APIs.
1616

1717
Enable Improved Auto Routing
1818
============================
@@ -36,15 +36,15 @@ Then, in **app/Config/Routing.php** confirm auto-routing is **enabled**:
3636
That's all you need for CodeIgniter to automatically map your controller classes and to URIs like ``GET /api/ping`` or ``POST /api/ping``.
3737

3838
Create a Ping controller
39-
=========================
39+
========================
4040

4141
To understand how a basic API endpoint works, let's generate a controller to serve as our first API endpoint. This will provide a simple "ping" response to confirm our setup is correct.
4242

4343
.. code-block:: console
4444
4545
php spark make:controller Api/Ping
4646
47-
This creates ``app/Controllers/Api/Ping.php``.
47+
This creates **app/Controllers/Api/Ping.php**.
4848

4949
Edit the file so it looks like this:
5050

@@ -100,7 +100,7 @@ Here's how other verbs would map if you added them later:
100100
+----------------------+--------------------------------+
101101

102102
Content Negotiation with the Format Class
103-
==========================================
103+
=========================================
104104

105105
By default, CodeIgniter uses the :php:class:`CodeIgniter\\Format\\Format` class to automatically negotiate the response format. It can return responses in either JSON or XML depending on what the client requests.
106106

user_guide_src/source/guides/api/index.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Getting Started with REST APIs
77
:local:
88
:depth: 2
99

10-
This tutorial will guide you through building a simple RESTful API to manage books using Codeigniter 4. Along the way, you'll leanr the basics of setting up a CodeIgniter project, configuring a database, and creating API endpoints, as well as understand what makes a RESTful API.
10+
This tutorial will guide you through building a simple RESTful API to manage books using Codeigniter4. Along the way, you'll leanr the basics of setting up a CodeIgniter project, configuring a database, and creating API endpoints, as well as understand what makes a RESTful API.
1111

1212
This tutorial will primarily focus on:
1313

@@ -85,7 +85,7 @@ Open ``.env`` and **uncomment** the database section, then set:
8585
database.default.hostname =
8686
database.default.port =
8787
88-
CodeIgniter will automatically create the SQLite database file if it doesn't exist, but you need to ensure that the ``writable/`` directory is writable by the web server.
88+
CodeIgniter will automatically create the SQLite database file if it doesn't exist, but you need to ensure that the **writable/** directory is writable by the web server.
8989

9090
.. warning::
9191

@@ -96,7 +96,7 @@ At this point, you should have a working CodeIgniter 4 project with SQLite confi
9696

9797
- The app starts with ``php spark serve``
9898
- ``CI_ENVIRONMENT`` is set to ``development`` in ``.env``
99-
- ``writable/database.db`` exists and is writable
99+
- **writable/database.db** exists and is writable
100100

101101
What's next
102102
===========

user_guide_src/source/guides/index.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Guides
33
######
44

5-
This section contains various guides to help you get started with CodeIgniter 4 in a project-based manner.
5+
This section contains various guides to help you get started with CodeIgniter4 in a project-based manner.
66

77
.. toctree::
88
:titlesonly:
@@ -20,4 +20,4 @@ This project walks you through building a basic news application. You will begin
2020
Build a RESTful API
2121
*******************
2222

23-
This guide will help you build a simple RESTful API using CodeIgniter 4. You will learn how to use auto-routing, setup controllers, and handle requests and responses in a RESTful manner. By the end of this guide, you will have a functional API that can perform CRUD operations on a resource. This will introduce you to the basic concepts of a RESTful API and the tools that CodeIgniter provides to facilitate its development.
23+
This guide will help you build a simple RESTful API using CodeIgniter4. You will learn how to use auto-routing, setup controllers, and handle requests and responses in a RESTful manner. By the end of this guide, you will have a functional API that can perform CRUD operations on a resource. This will introduce you to the basic concepts of a RESTful API and the tools that CodeIgniter provides to facilitate its development.

user_guide_src/source/index.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ Getting Started
1818

1919
installation/index
2020

21-
*******
21+
******
2222
Guides
23-
*******
23+
******
2424

2525
.. toctree::
2626
:includehidden:

0 commit comments

Comments
 (0)