Retrofit Mock Response

A library makes mock api from json files

License

License

Categories

Categories

Retrofit Net HTTP Clients
GroupId

GroupId

com.github.tientun
ArtifactId

ArtifactId

retrofit-mock-response
Last Version

Last Version

1.0.1
Release Date

Release Date

Type

Type

aar
Description

Description

Retrofit Mock Response
A library makes mock api from json files
Project URL

Project URL

https://github.com/tientun/Android-Retrofit-Mock-Response
Source Code Management

Source Code Management

https://github.com/tientun/Android-Retrofit-Mock-Response

Download retrofit-mock-response

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.tientun/retrofit-mock-response/ -->
<dependency>
    <groupId>com.github.tientun</groupId>
    <artifactId>retrofit-mock-response</artifactId>
    <version>1.0.1</version>
    <type>aar</type>
</dependency>
// https://jarcasting.com/artifacts/com.github.tientun/retrofit-mock-response/
implementation 'com.github.tientun:retrofit-mock-response:1.0.1'
// https://jarcasting.com/artifacts/com.github.tientun/retrofit-mock-response/
implementation ("com.github.tientun:retrofit-mock-response:1.0.1")
'com.github.tientun:retrofit-mock-response:aar:1.0.1'
<dependency org="com.github.tientun" name="retrofit-mock-response" rev="1.0.1">
  <artifact name="retrofit-mock-response" type="aar" />
</dependency>
@Grapes(
@Grab(group='com.github.tientun', module='retrofit-mock-response', version='1.0.1')
)
libraryDependencies += "com.github.tientun" % "retrofit-mock-response" % "1.0.1"
[com.github.tientun/retrofit-mock-response "1.0.1"]

Dependencies

compile (1)

Group / Artifact Type Version
com.squareup.retrofit2 : retrofit jar 2.1.0

Project Modules

There are no modules declared in this project.

#Retrofit mock response CircleCI Maven Central

##Features

  • Create fake response from json files
  • Support http methods

##Usage

1. Include library

Maven dependency:

<dependency>
	<groupId>com.github.tientun</groupId>
	<artifactId>retrofit-mock-response</artifactId>
	<version>1.0.0</version>
</dependency>

or

Gradle dependency:

compile 'com.github.tientun:retrofit-mock-response:1.0.0'

2. Retrofit client configs

Create OkHttpClient and add FakeInterceptor(context)

final OkHttpClient client = new OkHttpClient
                       .Builder()
                       .addInterceptor(new FakeInterceptor(context))
                       .build();

Create Retrofit with baseUrl("http://mock.api")

final Retrofit retrofit = new Retrofit.Builder()
                       .addConverterFactory(GsonConverterFactory.create())
                       .baseUrl("http://mock.api")
                       .client(client)
                       .build();

3. Create asset folder "mock.api" debug type

src/debug/assets/mock.api/
                        api1/
                        api2/
                        api3/
                            index.json
                            getUsers.json
                            user.json
                            ...

License

Copyright 2016 Tien Hoang

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Versions

Version
1.0.1
1.0.0