Latest 1.0.2
Homepage https://github.com/CoderHarry/Melon
License MIT
Platforms ios 8.0
Authors

Melon is a Swift HTTP networking libray.

Install

current Version only support cocoapods.

pod 'Melon', '~> 1.0.1' 
pod update

Requirements

  • iOS 7.0+
  • Xcode 8(Swift 3)

Simple Using

GET:

Melon.GET("https://httpbin.org/get")
            .addHeaders(["a":"a", "b":"b"])
            .addParams(["name": "caiyanzhi", "age":26])
            .onNetworkError({ error in
            }).responseJSON { (jsonObject, response) in
                print("jsonObject : (jsonObject)" )
        }

POST:

 Melon.POST("https://httpbin.org/post")
            .addHeaders(["a":"a", "b":"b"])
            .addParams(["name": "caiyanzhi", "age":26])
            .onNetworkError({ error in
            }).responseJSON { (jsonObject, response) in
                print("jsonObject : (jsonObject)")
        }

upload:

let melon =
        Melon.POST("https://httpbin.org/post")
            .addHeaders(["a":"a", "b":"b"])
            .addParams(["name": "caiyanzhi", "age":26])
            .addFiles([formdata])
            .uploadProgress({ (bytesSent, totalBytesSent, totalBytesExpectedToSend) in
                Melon.Print("totalBytesSent:(totalBytesSent)")
                Melon.Print("totalBytesExpectedToSend:(totalBytesExpectedToSend)")
            })
            .onNetworkError({ error in
            }).responseJSON { (jsonObject, response) in
                print("jsonObject : (jsonObject)")
        }

download:

let melon =
        Melon.Download("https://www.google.co.jp/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png").onNetworkError ({ error in

        }).downloadProgress({ (bytesWritten, totalBytesWritten, totalBytesExpectedToWrite) in
            print("bytesWritten:(bytesWritten)")
            print("totalBytesWritten:(totalBytesWritten)")
            print("totalBytesExpectedToWrite:(totalBytesExpectedToWrite)")
            print("progress:(Double(totalBytesWritten) / Double(totalBytesExpectedToWrite))")
        }).responseData { (data, reponse) in
            if let data = data {
                let image = UIImage(data: data)
                print("image: (image)")
            }
        }

cancel:

you can use cancel method to cancel request

melon.cancel()
melon.cancel {
    // cancel callback
}

future will support

  • Setting SSL pinning
  • Queue
  • Others…

Source install

Clone all files in the Melon directory into your project.

Latest podspec

{
    "name": "Melon",
    "version": "1.0.2",
    "summary": "Swift http request",
    "description": "Melon is a Swift HTTP / HTTPS networking library for people",
    "homepage": "https://github.com/CoderHarry/Melon",
    "license": "MIT",
    "authors": {
        "Caiyanzhi": "[email protected]"
    },
    "source": {
        "git": "https://github.com/CoderHarry/Melon.git",
        "tag": "1.0.2"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "Melon/*",
    "pushed_with_swift_version": "3.0n3.1n3.1"
}

Pin It on Pinterest

Share This