@@ -22,22 +22,42 @@ For instance, in JSON-LD, you will get a collection like this:
22
22
23
23
You may want to use absolute URLs (for instance if resources are used in another API) or network paths instead.
24
24
25
- It can be configured globally:
25
+ ## Configure URL Generation Globally
26
+
27
+ It can be configured globally using one of the configurations below:
28
+
29
+ ### Configure URL Generation Globally using Symfony
26
30
27
31
``` yaml
28
32
# api/config/packages/api_platform.yaml
29
33
api_platform :
30
34
defaults :
31
35
url_generation_strategy : !php/const ApiPlatform\Api\UrlGeneratorInterface::ABS_URL
32
36
` ` `
37
+ ### Configure URL Generation Globally using Laravel
38
+
39
+ ` ` ` php
40
+ <?php
41
+ // config/api-platform.php
42
+ return [
43
+ // ....
44
+ ' defaults' => [
45
+ ' url_generation_strategy' => ApiPlatform\Api\UrlGeneratorInterface::ABS_URL
46
+ ],
47
+ ];
48
+ ```
49
+
50
+ ## Configure URL Generation for a Specific Resource
33
51
34
52
It can also be configured only for a specific resource:
35
53
36
54
<code-selector >
37
55
38
56
``` php
39
57
<?php
40
- // api/src/Entity/Book.php
58
+ // api/src/ApiResource/Book.php with Symfony or app/ApiResource/Book.php with Laravel
59
+
60
+ namespace App\ApiResource;
41
61
42
62
use ApiPlatform\Metadata\ApiResource;
43
63
use ApiPlatform\Api\UrlGeneratorInterface;
@@ -51,21 +71,23 @@ class Book
51
71
52
72
``` yaml
53
73
# api/config/api_platform/resources.yaml
74
+ # The YAML syntax is only supported for Symfony
54
75
resources :
55
- App\Entity \Book :
76
+ App\ApiResource \Book :
56
77
urlGenerationStrategy : !php/const ApiPlatform\Api\UrlGeneratorInterface::ABS_URL
57
78
` ` `
58
79
59
80
` ` ` xml
60
81
<?xml version="1.0" encoding="UTF-8" ?>
61
82
<!-- api/config/api_platform/resources.xml -->
83
+ <!-- The XML syntax is only supported for Symfony -->
62
84
63
85
<resources
64
86
xmlns="https://api-platform.com/schema/metadata/resources-3.0"
65
87
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
66
88
xsi:schemaLocation="https://api-platform.com/schema/metadata/resources-3.0
67
89
https://api-platform.com/schema/metadata/resources-3.0.xsd">
68
- <resource class="App\Entity \Book" urlGenerationStrategy="0" />
90
+ <resource class="App\ApiResource \Book" urlGenerationStrategy="0" />
69
91
</resources>
70
92
```
71
93
0 commit comments