# iOS: Working with Images from a Server

DevFeed: [iOS: Working with Images from a Server](<https://devfeed.tech/articles/ios-working-with-images-from-a-server-22307.md>)

Original publisher: [Read original article](<https://www.thecodedself.com/Swift-Send-Image-To-Server/>)

Author: Keegan Rush

Published: 2017-07-04T00:00:00Z

Content type: tutorial

Language: en

Sources: [The Coded Self](<https://devfeed.tech/sources/the-coded-self.md>)

Topics: [iOS](<https://devfeed.tech/topics/ios.md>), [Mobile](<https://devfeed.tech/topics/mobile.md>), [Swift](<https://devfeed.tech/topics/swift.md>), [Back end](<https://devfeed.tech/topics/backend.md>), [API](<https://devfeed.tech/topics/api.md>), [Server](<https://devfeed.tech/topics/server.md>)

Tags: [api](<https://devfeed.tech/tags/api.md>), [backend](<https://devfeed.tech/tags/backend.md>), [http](<https://devfeed.tech/tags/http.md>), [ios](<https://devfeed.tech/tags/ios.md>), [mobile](<https://devfeed.tech/tags/mobile.md>), [swift](<https://devfeed.tech/tags/swift.md>)

## AI overview

A tutorial showing how to build a Kitura Swift backend with REST endpoints that receive images and return the most recently received image, then connect it to an iOS app. It explains converting images between UIImage and Data when sending them over the service.

## Source excerpt

If you're a mobile app developer, at some point in time you're going to need to interact with a backend. One of the tasks you might need to do is to retrieve and display images from a server, or submit an image to that server. What format should the image be in when you're submitting it? How do you convert bytes received from a service call into an image? Let's build the entire stack from the server to an iOS App to find out how. Setting up a backend We'll start off by building a Kitura server that provides a RESTful API to do two things: Receive images from a client Provide the most recent image that was received to a client I've put the finished server up on my Github. Create the server project Make a directory, and init a new executable Swift package. mkdir mkdir SwiftImageServer && cd SwiftImageServer swift package init --type executable Edit your Package.swift file to specify that you require the Kitura package. import PackageDescription let package = Package( name: "SwiftImageServer", dependencies: [ .Package(url: "https://github.com/IBM-Swift/Kitura.git", majorVersion: 1) ]) You can run a swift package fetch and you should see SwiftPM cloning Kitura and everything that it requires. Spin up a xcodeproj with swift package generate-xcodeproj and let's get coding! Create a Kitura server The backend is going to be super simple, so we'll just be working in main.swift. Let's start off by adding all the boilerplate that we need: import Kitura import Foundation // Create a Router that we can use to create REST endpoints let router = Router() // Specify that we want an HTTP server that we can reach with http://localhost:8090 Kitura.addHTTPServer(onPort: 8090, with: router) // Start the server Kitura.run() I love how easy it is to create something these days. Three lines of code and you have a server running. It's a shame that it can't do much. Let's fix that. Returning an image from a GET endpoint var latestImage: Data? = nil // http://localhost:8090/latestImage router