Repository: wagtail/wagtail

Issue:
Use Full URL for ImageRenditionField.
### Is your proposal related to a problem?

<!--
  Provide a clear and concise description of what the problem is.
  For example, "I'm always frustrated when..."
-->

I'm a big fan of the new `full_url` field that images have and would like them to be easily used in the API.

Assuming one's frontend app is living on a different domain to the Wagtail API then the default relative URLs aren't as useful.

### Describe the solution you'd like

<!--
  Provide a clear and concise description of what you want to happen.
-->

Add `full_url` to the output of `ImageRenditionField`.

I propose it just replace the `url` field altogether, but both could be returned.

### Describe alternatives you've considered

<!--
  Let us know about other solutions you've tried or researched.
-->

I've been extending the `ImageRenditionField` for use in my own projects

### Additional context

<!--
  Is there anything else you can add about the proposal?
  You might want to link to related issues here, if you haven't already.
-->

(Write your answer here.)

Use Full URL for ImageRenditionField.
### Is your proposal related to a problem?

<!--
  Provide a clear and concise description of what the problem is.
  For example, "I'm always frustrated when..."
-->

I'm a big fan of the new `full_url` field that images have and would like them to be easily used in the API.

Assuming one's frontend app is living on a different domain to the Wagtail API then the default relative URLs aren't as useful.

### Describe the solution you'd like

<!--
  Provide a clear and concise description of what you want to happen.
-->

Add `full_url` to the output of `ImageRenditionField`.

I propose it just replace the `url` field altogether, but both could be returned.

### Describe alternatives you've considered

<!--
  Let us know about other solutions you've tried or researched.
-->

I've been extending the `ImageRenditionField` for use in my own projects

### Additional context

<!--
  Is there anything else you can add about the proposal?
  You might want to link to related issues here, if you haven't already.
-->

(Write your answer here.)



Discussion:
As a small enhancement we could add the full url alongside existing url, this way we don't have a backwards compatibility issue. 

Marking as a good first issue for someone who wants to look at how the API works. 

Also recommend we do the same change for documents. 
I'll give it a shot
As a small enhancement we could add the full url alongside existing url, this way we don't have a backwards compatibility issue. 

Marking as a good first issue for someone who wants to look at how the API works. 

Also recommend we do the same change for documents. 
I'll give it a shot

Resolving patch:
diff --git a/wagtail/images/api/fields.py b/wagtail/images/api/fields.py
--- a/wagtail/images/api/fields.py
+++ b/wagtail/images/api/fields.py
@@ -13,6 +13,7 @@ class ImageRenditionField(Field):
     Example:
     "thumbnail": {
         "url": "/media/images/myimage.max-165x165.jpg",
+        "full_url": "https://media.example.com/media/images/myimage.max-165x165.jpg",
         "width": 165,
         "height": 100,
         "alt": "Image alt text"
@@ -37,6 +38,7 @@ def to_representation(self, image):
             return OrderedDict(
                 [
                     ("url", thumbnail.url),
+                    ("full_url", thumbnail.full_url),
                     ("width", thumbnail.width),
                     ("height", thumbnail.height),
                     ("alt", thumbnail.alt),


Test patch:
diff --git a/wagtail/images/tests/test_api_fields.py b/wagtail/images/tests/test_api_fields.py
--- a/wagtail/images/tests/test_api_fields.py
+++ b/wagtail/images/tests/test_api_fields.py
@@ -15,8 +15,11 @@ def setUp(self):
     def test_api_representation(self):
         rendition = self.image.get_rendition("width-400")
         representation = ImageRenditionField("width-400").to_representation(self.image)
-        self.assertEqual(set(representation.keys()), {"url", "width", "height", "alt"})
+        self.assertEqual(
+            set(representation.keys()), {"url", "full_url", "width", "height", "alt"}
+        )
         self.assertEqual(representation["url"], rendition.url)
+        self.assertEqual(representation["full_url"], rendition.full_url)
         self.assertEqual(representation["width"], rendition.width)
         self.assertEqual(representation["height"], rendition.height)
         self.assertEqual(representation["alt"], rendition.alt)