strongloop-community / loopback-sdk-ios

iOS Client SDK for the LoopBack framework.
Other
76 stars 39 forks source link

Correct usage od SDK #102

Open mpycio opened 8 years ago

mpycio commented 8 years ago

Hi, Following example for ios, I have following code:

    let adapter = LBRESTAdapter(URL: NSURL(string: "http://polis.dev:3000/api/v1/"), allowsInvalidSSLCertificate: true)
    let repository = adapter.repositoryWithClass(PolisUserRepository.classForCoder())
    let user = repository.modelWithDictionary([
        "email": "mpycio@email.com",
        "password": "password"
        ]) as! PolisUser;

    user.saveWithSuccess({ () -> Void in
        NSLog("user saved")
        }) { (error:NSError!) -> Void in
            NSLog("")
    }

saveWithSuccess always results in 404, because URL is constructed with 'prototype' path: URL: http://polis.dev:3000/api/v1/polisUser/prototype/create?...

What am I doing wrong, API explorer doesn't append 'prototype' in request URL

hideya commented 8 years ago

It is weird... It looks like you created a model named PolisUser. Have you write any custom SLRESTContract for that class? (or its super classes?)

BTW, this would not be related, but, is there any particular reason for saying PolisUserRepository.classForCoder() instead of just PolisUserRepository when creating the repository?

mpycio commented 8 years ago

I'm using LBx set of classes not SLx and trying to follow this guide: https://docs.strongloop.com/display/public/LB/iOS+SDK. So my PolisUser extends LBPersistedModel, I may be doing it all wrong ;).

hideya commented 8 years ago

@mpycio I see. So, your PolisUser class is a regular LBPersistedModel and it doesn't involve any custom SLRESTContract. Hmm... Could you try this and see if it works? https://github.com/hideya/loopback-swift-simple-example