I am a Swift beginner so apologies. With Siesta, I want to make a post request in a ViewController and then have the Entry object the request returns added to the TableViewController. In my ViewController:

EntryAPI.sharedInstance.addEntry()

The API code:

 func addEntry()  -> Request {
        return newEntry().request(.post, json:["foo": "bar"])
    }

func newEntry() -> Resource {
        return service
            .resource("/entry")
    }

After the post request the ViewController does an unwind segue to the TableViewController, of course before the post request completes. I am not sure where in the code I would take the response and call a function in the TableViewController that appends the new Entry object to the entry list.

I am not sure if I should pass the new Entry object from the addEntry() function to the TableViewController with onSuccess() or if the TableViewController can have the newEntry() resource and know when the post request completes. I am not sure if I am going about this in the right way either. Thanks in advance.

1

There are 1 answers

0
Mickey Barcia On

I am able to add the newEntry() resource to the TableViewController and change the API method:

func addEntry()  -> Request {
        let resource = newEntry()
        return resource.load(using: resource.request(.post, json:
            ["foo": "bar"]).onSuccess {_ in})
    }

Now resourceChanged function will be called where I can handle the response object. Answer was in the documentation.