Skip to content

Commit

Permalink
Release/0.7.0 (#59)
Browse files Browse the repository at this point in the history
* post content created

* added cat gif to test resources

* test for the bad input

* put contentType into body() function parameter

fixed a typo in exception msg

* byte array support added

* content function restored; json and form can be initialized from string

* test added

* file bug fixed; body context refactored

* media type is lifted to body() function parameter

* lambdas replaced to a regular parameters for string() file() bytes()

* repackaging

* minor reformatting

* readme update

* @SInCE and @author markup for public classes

* setup of @author and @SInCE for public classes

* improved BodyContext

* fixes related to codacy report

* 0.7.0 release final
  • Loading branch information
rybalkinsd committed Jan 7, 2019
1 parent c05bbc6 commit dfb6707
Show file tree
Hide file tree
Showing 42 changed files with 501 additions and 267 deletions.
43 changes: 42 additions & 1 deletion README.md
Expand Up @@ -100,9 +100,14 @@ val response: Response = httpPost {
"email" to "john.doe@gmail.com" // email=john.doe@gmail.com
}
}
// or
body {
form("login=user&email=john.doe@gmail.com")
}
}
```


##### POST with `json` body.
`json` body has a `application/json` content type

Expand All @@ -120,9 +125,45 @@ val response: Response = httpPost {
"email" to "john.doe@gmail.com" // "email": "john.doe@gmail.com"
} // }
}
// or
body {
json("""{"login":"user","email":"john.doe@gmail.com"}""")
}
}
```

##### POST with various content type
In addition to `form` or `json` body content types it is possible to declare a custom content type.

`body` DSL support three data sources: `file()`, `bytes()` and `string()`

```kotlin
httpPost {
body("application/json") {
string("""{"login":"user","email":"john.doe@gmail.com"}""")
}
}
```

```kotlin
val imageFile = File(getResource("/cat.gif").toURI())
httpPost {
body(type = "image/gif") {
file(imageFile)
}
}
```

```kotlin
httpPost {
body { // content type is optional, null by default
bytes("string of bytes".toByteArray())
}
}
```



#### HEAD

You can use same syntax as in [GET](#get)
Expand Down Expand Up @@ -153,7 +194,7 @@ val response = httpDelete { }

### Async http calls

#### GET
#### async GET

##### `String.asyncHttpGet()` extension function
This function starts a new coroutine with *Unconfined* dispatcher.
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Expand Up @@ -11,7 +11,7 @@ plugins {
}

group = "io.github.rybalkinsd"
version = "0.7.0-SNAPSHOT"
version = "0.8.0-SNAPSHOT"

repositories {
mavenCentral()
Expand Down
Expand Up @@ -24,6 +24,8 @@ import javax.net.ssl.SSLSocketFactory
* https://youtrack.jetbrains.com/issue/KT-3110
* will be implemented
*
* @since 0.5.0
* @author sergey
*/
interface ClientBuilder : ForkClientBuilder {
@get:Deprecated(level = DeprecationLevel.ERROR, message = "Write only field")
Expand Down
Expand Up @@ -21,6 +21,9 @@ import javax.net.ssl.SSLSocketFactory

/**
* DSL builder for OkHttpClient
*
* @since 0.5.0
* @author sergey
*/
fun client(block: ClientBuilder.() -> Unit) = ClientBuilderImpl().apply(block).build()

Expand Down
Expand Up @@ -26,7 +26,8 @@ import java.util.concurrent.TimeUnit
* For specific needs it's possible to fork `defaultHttpClient`
* @see `io.github.rybalkinsd.kohttp.client.OkHttpClientExtKt.fork`
*
* @author sergey 21/07/2018
* @since 0.0.1
* @author sergey
*/
val defaultHttpClient: OkHttpClient = config.client.let {
client {
Expand Down
Expand Up @@ -2,6 +2,10 @@ package io.github.rybalkinsd.kohttp.client

import okhttp3.OkHttpClient


/**
*
* @since 0.5.0
* @author sergey
*/
fun OkHttpClient.fork(block: ForkClientBuilder.() -> Unit) : OkHttpClient =
ClientBuilderImpl(this).apply(block).build()
142 changes: 0 additions & 142 deletions src/main/kotlin/io/github/rybalkinsd/kohttp/dsl/HttpContext.kt

This file was deleted.

12 changes: 4 additions & 8 deletions src/main/kotlin/io/github/rybalkinsd/kohttp/dsl/HttpDeleteDsl.kt
@@ -1,7 +1,7 @@
package io.github.rybalkinsd.kohttp.dsl

import io.github.rybalkinsd.kohttp.client.defaultHttpClient
import io.github.rybalkinsd.kohttp.dsl.Method.DELETE
import io.github.rybalkinsd.kohttp.dsl.context.HttpDeleteContext
import okhttp3.Call
import okhttp3.Response

Expand Down Expand Up @@ -38,16 +38,12 @@ import okhttp3.Response
* </pre>
*
* @see Response
* @see HttpContext
* @see ParamContext
* @see HeaderContext
* @see BodyContext
* @see HttpDeleteContext
*
* Created by Sergey on 23/07/2018.
* @since 0.3.2
* @author sergey
*/
fun httpDelete(client: Call.Factory = defaultHttpClient, init: HttpDeleteContext.() -> Unit): Response {
val context = HttpDeleteContext().apply(init)
return client.newCall(context.makeRequest()).execute()
}

class HttpDeleteContext: HttpPostContext(method = DELETE)
9 changes: 4 additions & 5 deletions src/main/kotlin/io/github/rybalkinsd/kohttp/dsl/HttpGetDsl.kt
@@ -1,6 +1,7 @@
package io.github.rybalkinsd.kohttp.dsl

import io.github.rybalkinsd.kohttp.client.defaultHttpClient
import io.github.rybalkinsd.kohttp.dsl.context.HttpGetContext
import okhttp3.Call
import okhttp3.Response

Expand Down Expand Up @@ -35,12 +36,10 @@ import okhttp3.Response
* </pre>
*
* @see Response
* @see HttpContext
* @see ParamContext
* @see HeaderContext
* @see BodyContext
* @see HttpGetContext
*
* Created by Sergey on 22/07/2018
* @since 0.1.0
* @author sergey
*/
fun httpGet(client: Call.Factory = defaultHttpClient, init: HttpGetContext.() -> Unit): Response {
val context = HttpGetContext().apply(init)
Expand Down
@@ -1,6 +1,7 @@
package io.github.rybalkinsd.kohttp.dsl

import io.github.rybalkinsd.kohttp.client.defaultHttpClient
import io.github.rybalkinsd.kohttp.dsl.context.HttpHeadContext
import okhttp3.Call
import okhttp3.Response

Expand Down Expand Up @@ -35,11 +36,10 @@ import okhttp3.Response
* </pre>
*
* @see Response
* @see HttpContext
* @see ParamContext
* @see HeaderContext
* @see BodyContext
* @see HttpHeadContext
*
* @since 0.1.0
* @author sergey
*/
fun httpHead(client: Call.Factory = defaultHttpClient, init: HttpHeadContext.() -> Unit): Response {
val context = HttpHeadContext().apply(init)
Expand Down
@@ -1,6 +1,7 @@
package io.github.rybalkinsd.kohttp.dsl

import io.github.rybalkinsd.kohttp.client.defaultHttpClient
import io.github.rybalkinsd.kohttp.dsl.context.HttpPatchContext
import okhttp3.Call
import okhttp3.Response

Expand Down Expand Up @@ -37,12 +38,10 @@ import okhttp3.Response
* </pre>
*
* @see Response
* @see HttpContext
* @see ParamContext
* @see HeaderContext
* @see BodyContext
* @see HttpPatchContext
*
* Created by Bpaxio on 06/09/2018.
* @since 0.2.0
* @author Bpaxio
*/
fun httpPatch(client: Call.Factory = defaultHttpClient, init: HttpPatchContext.() -> Unit): Response {
val context = HttpPatchContext().apply(init)
Expand Down
@@ -1,6 +1,7 @@
package io.github.rybalkinsd.kohttp.dsl

import io.github.rybalkinsd.kohttp.client.defaultHttpClient
import io.github.rybalkinsd.kohttp.dsl.context.HttpPostContext
import okhttp3.Call
import okhttp3.Response

Expand Down Expand Up @@ -37,12 +38,10 @@ import okhttp3.Response
* </pre>
*
* @see Response
* @see HttpContext
* @see ParamContext
* @see HeaderContext
* @see BodyContext
* @see HttpPostContext
*
* Created by Sergey on 23/07/2018.
* @since 0.2.0
* @author sergey
*/
fun httpPost(client: Call.Factory = defaultHttpClient, init: HttpPostContext.() -> Unit): Response {
val context = HttpPostContext().apply(init)
Expand Down

0 comments on commit dfb6707

Please sign in to comment.