NotAPI allows you to swiftly generate a mock API, providing an efficient way to test your applications.
npm install -g not-api
not-api
NPX is a tool that comes with npm, allowing you to execute Node.js packages without having to install them globally. In this case, we're using NPX to run the not-api
package.
To run not-api
with NPX, use the following command:
npx not-api
Flag | Description | Default |
---|---|---|
-d |
Specifies the directory where the mock json files are located. | .not-api |
-p |
Defines the API port. | 5010 |
-o |
Specify the URL of the API to be intercepted. | none |
Warning: Port 5022 is reserved for notAPI's internal API and is not available for other uses.
To connect your physical Android device to the localhost for testing, you need to use the adb reverse
command. This command redirects the network traffic from a specific port on your device to a port on your local machine.
Run the following command:
adb reverse tcp:5010 tcp:5010
not-api -p 5009
not-api -o https://my-url-api.io
not-api -d ./mock-api
{
"uri": "/login",
"method": "POST",
"responses": [
{
"name": "Success Login",
"statusCode": 200,
"delay": 200,
"response": {
"token": "eyJhbGciOiJIUzI1NiIsInR4cCI6IkpXVCJ8.eyJzdWIiOi",
"name": "John Doe"
}
},
{
"name": "Error Contraseña inválida",
"statusCode": 401,
"delay": 100,
"response": {
"code": "E001",
"message": "Contraseña inválida"
}
}
]
}