This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
enum HttpMethod:String{ | |
case get = "get" | |
case post = "post" | |
} | |
let BaseURL : String = "http://dummy.restapiexample.com/api/v1/" | |
class NetworkManager { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class ViewController: UIViewController { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
NetworkManager.shared.dataTask(serviceURL: "employees", httpMethod: .get, parameters: nil) { (response, error) in | |
if response != nil { | |
print(response) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class ViewController: UIViewController { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
NetworkManager.shared.dataTask(serviceURL: "create", httpMethod: .post, parameters: ["name":"rinto","salary":"456","age":"30"]) { (response, error) in | |
if response != nil { | |
print(response) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"userId": "rirani", | |
"jobTitleName": "Developer", | |
"firstName": "Romin", | |
"lastName": "Irani", | |
"preferredFullName": "Romin Irani", | |
"employeeCode": "E1", | |
"region": "CA", | |
"phoneNumber": "408-1234567", | |
"emailAddress": "[email protected]", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct UserInfo: Codable{ | |
var userId: String | |
var jobTitleName: String | |
var firstName: String | |
var lastName: String | |
var preferredFullName: String | |
var employeeCode: String | |
var region: String | |
var phoneNumber: String | |
var emailAddress: String |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let decoder = JSONDecoder() | |
let model = try? decoder.decode(UserInfo.self, from:jsonData) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct UserInfo: Codable{ | |
var userId: String | |
var jobTitleName: String | |
var userfirstName: String | |
var userlastName: String | |
var preferredFullName: String | |
var employeeCode: String | |
var region: String | |
var phoneNumber: String | |
var emailAddress: String |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"userId": "rirani", | |
"jobTitleName": "Developer", | |
"name": { | |
"firstname": "rinto", | |
"lastname": "andrews" | |
}, | |
"preferredFullName": "Romin Irani", | |
"employeeCode": "E1", | |
"region": "CA", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct UserInfo { | |
var userId: String | |
var jobTitleName: String | |
var firstName: String | |
var lastName: String | |
var preferredFullName: String | |
var employeeCode: String | |
var region: String | |
var phoneNumber: String | |
var emailAddress: String |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"userId": "rirani", | |
"jobTitleName": "Developer", | |
"name": { | |
"firstname": "rinto", | |
"lastname": "andrews" | |
} | |
} |
OlderNewer