Skip to content

Instantly share code, notes, and snippets.

View rintoandrews90's full-sized avatar
:octocat:

Rinto Andrews rintoandrews90

:octocat:
View GitHub Profile
import Foundation
enum HttpMethod:String{
case get = "get"
case post = "post"
}
let BaseURL : String = "http://dummy.restapiexample.com/api/v1/"
class NetworkManager {
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)
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)
{
"userId": "rirani",
"jobTitleName": "Developer",
"firstName": "Romin",
"lastName": "Irani",
"preferredFullName": "Romin Irani",
"employeeCode": "E1",
"region": "CA",
"phoneNumber": "408-1234567",
"emailAddress": "[email protected]",
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
let decoder = JSONDecoder()
let model = try? decoder.decode(UserInfo.self, from:jsonData)
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
{
"userId": "rirani",
"jobTitleName": "Developer",
"name": {
"firstname": "rinto",
"lastname": "andrews"
},
"preferredFullName": "Romin Irani",
"employeeCode": "E1",
"region": "CA",
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
{
"userId": "rirani",
"jobTitleName": "Developer",
"name": {
"firstname": "rinto",
"lastname": "andrews"
}
}