Skip to content

Commit ac6fa54

Browse files
author
Dmitry Zaytsev
committed
Added Endpoint2mock README
1 parent 4bc3ccf commit ac6fa54

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed

README.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# Endpoint2mock
2+
3+
## Add it to your project
4+
5+
### Step one
6+
7+
Add `jitpack.io` to the list of your repositories.
8+
9+
```groovy
10+
repositories {
11+
maven { url 'https://jitpack.io' }
12+
}
13+
```
14+
15+
### Step two
16+
17+
Add dependencies.
18+
19+
```groovy
20+
compile 'com.github.car2go.Endpoint2mock:endpoint2mock:1.0.0'
21+
22+
// If you use Kotlin
23+
kapt 'com.github.car2go.Endpoint2mock:endpoint2mock-compiler:1.0.0'
24+
25+
// If you do not use Kotlin
26+
apt 'com.github.car2go.Endpoint2mock:endpoint2mock-compiler:1.0.0'
27+
```
28+
29+
### Step three
30+
31+
Add `@MockedEndpoint` annotation to your Retrofit interface. For the sake of example let's use Github API.
32+
33+
```kotlin
34+
interface GithubApi {
35+
36+
/**
37+
* Will call mocked server if MockableClient is enabled.
38+
*/
39+
@MockedEndpoint
40+
@GET("/users/car2go/repos")
41+
fun getCompanyRepositories(): Observable<List<Repository>>
42+
43+
/**
44+
* This endpoint will not be mocked and requests will be sent to the real server.
45+
*/
46+
@GET("/users/dmitry-zaitsev/repos")
47+
fun getUserRepositories(): Observable<List<Repository>>
48+
49+
}
50+
```
51+
52+
### Step four
53+
54+
Use `MockableClient` as client for your Retrofit builder.
55+
56+
```kotlin
57+
RestAdapter.Builder()
58+
.setClient(
59+
MockableClient.build(mockServerUrl) // Assuming that you have something running at this URL
60+
.mockWhen { shouldMockRequests() }
61+
.build()
62+
)
63+
.setEndpoint("https://api.github.com") // In this case we are using Github API
64+
.build()
65+
.create(GithubApi::class.java)
66+
```
67+
68+
You can check [json-server](https://github.com/car2go/Endpoint2mock/tree/master/json-server) folder for an example of mock server.
69+
70+
And you are ready to go!
71+
72+
## License
73+
74+
```
75+
Copyright 2017 car2go group GmbH
76+
77+
Released under the MIT license.
78+
79+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
80+
81+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
82+
83+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
84+
```

0 commit comments

Comments
 (0)