Skip to content

Commit 4724535

Browse files
Merge pull request #116 from utopia-php/chore-rename-to-http
chore: rename library to utopia-php/http
2 parents 6b6ae76 + 4a3ffd2 commit 4724535

5 files changed

Lines changed: 39 additions & 36 deletions

File tree

.github/workflows/test.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ jobs:
1515
with:
1616
php-version: '8.1'
1717

18+
- name: Validate composer.json and composer.lock
19+
run: composer validate --strict
20+
1821
- name: Setup Docker
1922
run: docker-compose up -d --build
2023

@@ -23,6 +26,6 @@ jobs:
2326

2427
- name: Run FPM Tests
2528
run: docker compose exec fpm vendor/bin/phpunit --configuration phpunit.xml
26-
29+
2730
- name: Run Swoole Tests
2831
run: docker compose exec swoole vendor/bin/phpunit --configuration phpunit.xml

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ Http::init()
204204
});
205205
```
206206

207-
Groups are designed to be actions that run during the lifecycle of requests to endpoints that have some logic in common. Groups allow you to prevent code duplication and are designed to be defined anywhere in your source code to allow flexibility.
207+
Groups are designed to be actions that run during the lifecycle of requests to endpoints that have some logic in common. Groups allow you to prevent code duplication and are designed to be defined anywhere in your source code to allow flexibility.
208208

209209
### Resources
210210

@@ -254,7 +254,7 @@ Utopia Http requires PHP 8.0 or later. We recommend using the latest PHP version
254254

255255
Our ecosystem supports other thin PHP projects aiming to extend the core PHP Utopia Http.
256256

257-
Each project is focused on solving a single, very simple problem and you can use composer to include any of them in your next project.
257+
Each project is focused on solving a single, very simple problem and you can use composer to include any of them in your next project.
258258

259259
You can find all libraries in [GitHub Utopia organization](https://github.com/utopia-php).
260260

composer.lock

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/Getting-Starting-Guide.md

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Utopia Http is an easy-to-use PHP MVC based framework with minimal must-have features for professional, simple, advanced and secure web development. It follows an architecture like Express and is based on the declarative programming approach. Documenting and writing code are usually seen as two separate tasks and very often, documentation loses priority in the software development lifecycle. Utopia unifies the two with a flexible API that allows your code to be self-documenting. What’s interesting about Utopia is its ability to accept metadata along with it’s route definitions. This metadata can then be used for various purposes like generating documentation, swagger specifications and more.
55

66
# Defining Routes
7-
If you’re new to Utopia, let’s get started by looking at an example of a basic GET route for an application that you can create using Utopia. We'll be using a [Swoole server](https://github.com/swoole/swoole-src) in this example, but you should be able to extend it to any HTTP server.
7+
If you’re new to Utopia, let’s get started by looking at an example of a basic GET route for an application that you can create using Utopia. We'll be using a [Swoole server](https://github.com/swoole/swoole-src) in this example, but you should be able to extend it to any HTTP server.
88

99
## Basic GET Route
1010

@@ -17,7 +17,7 @@ use Swoole\Http\Request as SwooleRequest;
1717
use Swoole\Http\Response as SwooleResponse;
1818

1919
$http = new Server("0.0.0.0", 8080);
20-
20+
2121
Http::get('/')
2222
->inject('request')
2323
->inject('response')
@@ -27,7 +27,7 @@ Http::get('/')
2727
$response->send("<div> Hello World! </div>");
2828
}
2929
/*
30-
Configure your HTTP server to respond with the Utopia http.
30+
Configure your HTTP server to respond with the Utopia http.
3131
*/
3232

3333
$http->on('request', function (SwooleRequest $swooleRequest, SwooleResponse $swooleResponse) {
@@ -39,12 +39,12 @@ $http->on('request', function (SwooleRequest $swooleRequest, SwooleResponse $swo
3939

4040
$http->start();
4141
```
42-
42+
4343

4444
Any route in Utopia would require you to `inject` the dependencies ( `$request` and `$response` in this case ) and define the controller by passing a callback to the `action` function. As you might have already guessed, `$request` and `$response` refer to the objects of the HTTP server library you’re using, for example, Swoole in this case. `action` defines the callback function that would be called when the GET request is executed. In this case, raw HTML is returned as a `$response`.
4545

4646
## More Endpoints
47-
You can perform basic CRUD operations like GET, POST, PUT and DELETE using Utopia. Let’s assume there's a file `todos.json` that stores a list of todo objects with the following structure. In a real-world scenario, you would be fetching this information from a database.
47+
You can perform basic CRUD operations like GET, POST, PUT and DELETE using Utopia. Let’s assume there's a file `todos.json` that stores a list of todo objects with the following structure. In a real-world scenario, you would be fetching this information from a database.
4848

4949
```json
5050
[
@@ -88,9 +88,9 @@ You might have noticed an additional property in the above example, i.e. `param`
8888
All the parameters need to be defined using the `param` property which accepts the following - `$key`, `$default`, `$validator`, `$description`, `$optional` and `$injections`.
8989

9090
There are typically 3 types of parameters:
91-
1. Path params ( eg: `/api/users/<userID>` )
91+
1. Path params ( eg: `/api/users/<userID>` )
9292
2. Query Params ( eg: `/api/users?userId=<userID>`)
93-
3. Body Params ( These are passed in the request body in POST and PUT requests. )
93+
3. Body Params ( These are passed in the request body in POST and PUT requests. )
9494

9595
Let's take a look at how these three types of params are taken care of by Utopia:
9696

@@ -100,7 +100,7 @@ Let's take a look at how these three types of params are taken care of by Utopia
100100

101101
3. Body Parameters are specified using the `->param()` function as well.
102102

103-
Each of these params then become available to the `->action()` callback function in the same order that they were declared in.
103+
Each of these params then become available to the `->action()` callback function in the same order that they were declared in.
104104

105105
### Returning a Response
106106
Based on the type of the response you wish to return, multiple options can be used:
@@ -120,7 +120,7 @@ $response->json(['Goodbye' => 'World']);
120120
JSON objects can be returned by passing the JSON object inside `$response->json()`.
121121

122122

123-
### Setting Response Status
123+
### Setting Response Status
124124

125125
You can set a status code for your response using the `setStatusCode()` function of utopia's response object.
126126

@@ -149,28 +149,28 @@ use Utopia\Http\Validator\Wildcard;
149149
$http = new Server("0.0.0.0", 8080);
150150

151151
Http::init(function($response) {
152-
/*
153-
Example of global init method. Do stuff that is common to all your endpoints in all groups.
152+
/*
153+
Example of global init method. Do stuff that is common to all your endpoints in all groups.
154154
This can include things like authentication and authorisation checks, implementing rate limits and so on..
155155
*/
156156
}, ['response']);
157157

158158
Http::init(function($response) {
159-
/*
159+
/*
160160
Example of init method for group1. Do stuff that is common to all your endpoints in group1.
161161
This can include things like authentication and authorisation checks, implementing rate limits and so on..
162162
*/
163163
}, ['response'], 'group1');
164164

165165
Http::init(function($response) {
166-
/*
167-
Example of init method for group2. Do stuff that is common to all your endpoints in group2.
166+
/*
167+
Example of init method for group2. Do stuff that is common to all your endpoints in group2.
168168
This can include things like authentication and authorisation checks, implementing rate limits and so on..
169169
*/
170170
}, ['response'], 'group2');
171171

172172
Http::shutdown(function($request) {
173-
/*
173+
/*
174174
Example of global shutdown method. Do stuff that needs to be performed at the end of each request for all groups.
175175
'*' (Wildcard validator) is optional.
176176
This can include cleanups, logging information, recording usage stats, closing database connections and so on..
@@ -179,7 +179,7 @@ Http::shutdown(function($request) {
179179
}, ['request'], '*');
180180

181181
Http::shutdown(function($request) {
182-
/*
182+
/*
183183
Example of shutdown method of group1. Do stuff that needs to be performed at the end of each request for all groups.
184184
This can include cleanups, logging information, recording usage stats, closing database connections and so on..
185185
*/
@@ -211,7 +211,7 @@ Http::put('/todos/:id')
211211
$response->json($data);
212212
}
213213
);
214-
214+
215215
$http->start();
216216
```
217217

@@ -224,7 +224,7 @@ For each endpoint, you can add the following properties described below. Let’s
224224
`groups` are used to define common functions that need to be executed. When you add a callback function to a group, the init hooks of the respective group are executed before the individual actions are executed.
225225

226226
* #### Labels
227-
`label` can be used to store metadata that is related to your endpoint. It’s a key-value store. Some use-cases can be using label to generate the documentation or the swagger specifications.
227+
`label` can be used to store metadata that is related to your endpoint. It’s a key-value store. Some use-cases can be using label to generate the documentation or the swagger specifications.
228228

229229
* #### Injections
230230
Since each action in Utopia depends on certain resources, `inject` is used to add the dependencies. `$response` and `$request` can be injected into the service. Utopia provides the http static functions to make global resources available to all utopia endpoints.
@@ -238,7 +238,7 @@ Since each action in Utopia depends on certain resources, `inject` is used to ad
238238
Now that you’re familiar with routing in Utopia, let’s dive into the lifecycle of a utopia request in detail and learn about some of the lifecycle methods.
239239

240240
## Init and Shutdown Methods
241-
241+
242242
The Utopia http goes through the following lifecycle whenever it receives any request:
243243

244244
![untitled@2x](https://user-images.githubusercontent.com/43381712/146966398-0f4af03b-213e-47d7-9002-01983053c5aa.png)
@@ -248,17 +248,17 @@ In case an error occurs anywhere during the execution, the workflow executes the
248248
The init and shutdown methods take three params:
249249

250250
1. Callback function
251-
2. Array of resources required by the callback
251+
2. Array of resources required by the callback
252252
3. The endpoint group for which the callback is intended to run
253253

254254
* ### Init
255255

256256
init method is executed in the beginning when the program execution begins. Here’s an example of the init method, where the init method is executed for all groups indicated by the wildcard symbol `'*'`.
257257
```php
258258
Http::init(function($response) {
259-
/*
260-
Do stuff that is common to all your endpoints.
261-
This can include things like authentication and authorisation checks, implementing rate limits and so on..
259+
/*
260+
Do stuff that is common to all your endpoints.
261+
This can include things like authentication and authorisation checks, implementing rate limits and so on..
262262
*/
263263
}, ['response'], '*');
264264
```
@@ -269,8 +269,8 @@ Utopia's shutdown callback is used to perform cleanup tasks after a request. Thi
269269

270270
```php
271271
Http::shutdown(function($request) {
272-
/*
273-
Do stuff that needs to be performed at the end of each request.
272+
/*
273+
Do stuff that needs to be performed at the end of each request.
274274
This can include cleanups, logging information, recording usage stats, closing database connections and so on..
275275
*/
276276

example/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "utopia-php/http-app",
33
"require": {
4-
"utopia-php/http": "0.33.*"
4+
"utopia-php/http": "latest"
55
}
66
}

0 commit comments

Comments
 (0)