View on GitHub

Mobile App Development (MAD)

Mobile App Development class for University of Applied Sciences Vienna

REST Exercise

In this exercise we’ll hook up our login screen from the previous exercise with a real API.

The main goal of this exercise is for you to learn how to query REST APIs using URLSession.

Deadline

See the deadline on the exercises page.

Submission instructions

See the submission instructions on the exercises page.

API Key, Username, Password

In this exercise, we’re going to use the REST API of the Google Firebase service. Specifically, we’re going to use this endpoint to sign in with an email/password combo. You shouldn’t necessarily have to dig through the docs above to be able to complete this exercise. Everything you need should be in the instructions below, but the above link might still help you understand the inner workings of the API.

When using the API, use the following credentials:

Note that I intentionally chose a short email/password combo to make testing easier for you so you don’t have to type so much. Since this user account doesn’t have access to any important data, security isn’t really a concern.

Instructions, Requirements and Hints

Setting up the project

Setting up the login request

{
	"email": "YOUR_EMAIL"
	"password": "YOUR_PASSWORD",
	"returnSecureToken": true
}
{
  "kind": "identitytoolkit#VerifyPasswordResponse",
  "localId": "CxlvybnrRnSZyDDXN2VS7Fr6ddk1",
  "email": "YOUR_EMAIL",
  "displayName": "",
  "idToken": "VERY_LONG_ID_TOKEN",
  "registered": true,
  "refreshToken": "REFRESH_TOKEN",
  "expiresIn": "3600"
}

Properly parsing the response

Handling errors

{
  "error": {
    "code": 400,
    "message": "INVALID_EMAIL",
    "errors": [
      {
        "message": "INVALID_EMAIL",
        "domain": "global",
        "reason": "invalid"
      }
    ]
  }
}

Creating a completion handler and forwarding the user/error

	DispatchQueue.main.async {
			completionHandler(user, nil)
	}

Help and Support

As always, if you need any help or have any questions, feel free to contact me. I’m happy to help!