All Projects → rodkranz → Fakeapi

rodkranz / Fakeapi

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Labels

Projects that are alternatives of or similar to Fakeapi

Api
API Oficial do Te Emprego
Stars: ✭ 73 (-3.95%)
Mutual labels:  api
Blog api tutorial
Blog API Written in Python Flask- Part 1: https://www.codementor.io/olawalealadeusi896/restful-api-with-python-flask-framework-and-postgres-db-part-1-kbrwbygx5 Part 2: https://www.codementor.io/olawalealadeusi896/building-a-restful-blog-apis-using-python-and-flask-part-2-l9y8awusp Part 3: https://www.codementor.io/olawalealadeusi896/building-a-restful-blog-apis-using-python-and-flask-part-3-lx7rt8pfk
Stars: ✭ 74 (-2.63%)
Mutual labels:  api
Ffsend Api
📬 A fully featured Firefox Send API client written in Rust.
Stars: ✭ 75 (-1.32%)
Mutual labels:  api
Mojo Weixin
使用Perl语言(不会没关系)编写的个人账号微信/weixin/wechat客户端框架(非GUI),可通过插件提供基于HTTP协议的api接口供其他语言或系统调用
Stars: ✭ 1,181 (+1453.95%)
Mutual labels:  api
Openvulnapi
Documentation and Tools for Cisco's PSIRT openVuln API
Stars: ✭ 73 (-3.95%)
Mutual labels:  api
Gock
HTTP traffic mocking and testing made easy in Go ༼ʘ̚ل͜ʘ̚༽
Stars: ✭ 1,185 (+1459.21%)
Mutual labels:  api
Tapi Yandex Metrika
Библиотека для всех API Яндекс Метрика
Stars: ✭ 74 (-2.63%)
Mutual labels:  api
Pinned
📌 Date based versioning system for Go APIs.
Stars: ✭ 77 (+1.32%)
Mutual labels:  api
Directions Api Js Client
JavaScript client for the GraphHopper Directions API
Stars: ✭ 73 (-3.95%)
Mutual labels:  api
Sec Edgar Financials
Extract financial data from the SEC's EDGAR database
Stars: ✭ 73 (-3.95%)
Mutual labels:  api
Checklist Tools Website
🍿 The perfect Checklist Website for meticulous developers.
Stars: ✭ 73 (-3.95%)
Mutual labels:  api
Pymarketcap
Python3 API wrapper and web scraper for https://coinmarketcap.com
Stars: ✭ 73 (-3.95%)
Mutual labels:  api
Spring Boot Api Project Seed
🌱🚀一个基于Spring Boot & MyBatis的种子项目,用于快速构建中小型API、RESTful API项目~
Stars: ✭ 8,979 (+11714.47%)
Mutual labels:  api
Materialchipview
Material Chip view. Can be used as tags for categories, contacts or creating text clouds
Stars: ✭ 1,181 (+1453.95%)
Mutual labels:  api
Modio Sdk Legacy
SDK for integrating mod.io into your game - a modding API for game developers
Stars: ✭ 75 (-1.32%)
Mutual labels:  api
Nextjs Jwt Example
next.js authorization example including private route protection
Stars: ✭ 72 (-5.26%)
Mutual labels:  api
Web Api The Good Parts
《Web API的设计与开发》--知识点整理
Stars: ✭ 74 (-2.63%)
Mutual labels:  api
Laravel Vue Starter
Well Documented Laravel Starter App From Development to Production. For Full Blown RESTFUL API and SPA with Beautiful UI Using Buefy / ElementUi For Reusable Vue Components
Stars: ✭ 76 (+0%)
Mutual labels:  api
Tinder Auto Matcher
Auto-match people who liked you on Tinder
Stars: ✭ 76 (+0%)
Mutual labels:  api
Zeal
Offline documentation browser inspired by Dash
Stars: ✭ 9,164 (+11957.89%)
Mutual labels:  api

Fake API

You don't need to wait for backend delivery your api any more, you can simulate the api response with this simple fakeApi, you can continue developing your frontend without dependencies.

It is a simple way to mock your api response.

Source

  • FakeApi Source
  • Version: 1.4.0
  • License: MIT-style

Summary

How to Compile it

You can see the full available binary list here or compile those files from different platforms in your owner computer.

Download

You can just download and use, without compile anything.

Download for Mac OSx

Download for Linux x386

Download for Linux amd64

Download for Windows x386

Download for Windows x64

Requirements to Build

If you want to build in your own computer you need follow this steps below, if you don't want to build you can download at links above.

  • GO Language
  • GO-Bindata - Component to help for settings
    • To install go get -u github.com/jteeuwen/go-bindata/...

Configure Bindata

Use the script init.sh or the command

$ go-bindata -o "./modules/bindata/bindata.go" -pkg "bindata" conf/*

Compiling to Linux

$ env GOOS=linux GOARCH=arm GOARM=7 go build -o server main.go

Compiling to MacOSX

$ env GOOS=darwin GOARCH=386 go build -o server main.go

Compiling to Windows

$ env GOOS=windows GOARCH=386 go build -o server.exe main.go

Execute

Execute ./server or ./server web to start server.

Seeds File

In a folder named ./fakes/default, you need to have the seed (json files) that will represent your api, the server will read all files inside folder and load them. Use the file name to define the URL of api.

P.S. All files seed needs to start with api_[ANYTHING].

e.g.: If file name is api_account_signup.json the url will be /api/account/signup.

The file seed needs to follow this format: the seed file needs to follow this rules, method_status_code: response (Response can be any format)

{
    "[METHOD]_[STATUS_CODE]": [RESPONSE]
}

Example seed format:

{
	"POST_200": {
        "response": "Post Request with status code 200",
        "statusCode: 200,
	}
}        

Example request:

curl -X POST "http://localhost:9090/api/account/signup"

Response will be:

{
	"response": "POST Request with status code 200",
	"statusCode: 200,
}

Multiples Response for seed

You can add more then one response in seeds file for the same method and different methods too, just follow the rule in seed.

E.g: Seed file name is api_account_user.json

{
   "GET_200": {
        "response": "GET Request with status code 200",
        "statusCode: 200,
	},
    "POST_400": {
        "response": "POST Request with status code 400",
        "statusCode: 400,
        "error": {
        	"email": "email has invalid format",
            "time": "the date is invalid"
        }
	}
    "POST_200": {
        "response": "Post Request with status code 200",
        "statusCode: 200,
	}
}

Request POST: when you are using multiple response and no specify the status code in your header request, the response will be random between data that you putting in your seed file.

curl -X POST "/api/account/user"

Response POST Dynamic:

{
	"response": "POST Request with status code 400",
	"statusCode: 400,
	"error": {
		"email": "email has invalid format",
		"time": "the date is invalid"
	}
}

or

{
	"response": "Post Request with status code 200",
	"statusCode: 200,
}

Request POST: use the header X-Fake-Response-Code to specify the response that you want to receive.

curl -X POST -H "X-Fake-Response-Code: 400" "/api/account/user"

Response POST specific:

{
	"response": "POST Request with status code 400",
	"statusCode: 400,
	"error": {
		"email": "email has invalid format",
		"time": "the date is invalid"
	}
}

Multiples Response for some method

You can use multiple response for the same method and status for defined it you need to use as:

Request GET:

curl -X POST -H "X-Fake-Response-Index: 1" "/api/account/user"

Response GET specific position:

{
   "GET_200:0": {
        "response": "First response of GET 200",
        "statusCode: 200,
   },
   "GET_200:1": {
        "response": "Second response of GET 200",
        "statusCode: 200,
    },
}

If you specify slice by header as X-Fake-Response-Index: 1 the fakeApi will return data at position

Multiple Domains

if you want to use multiples domain you just add a new folder inside of folder fakes and use the header to specific the domain name.

if you don't want to use the custom domain you can use default folder for yours files seed.

Folders example:

➜  fakeApi git:(develop) ✗ ls -la fakes
total 0
drwxr-xr-x   3 rlopes  staff   102B 22 Dec 23:34 default/
drwxr-xr-x   8 rlopes  staff   272B 23 Dec 00:11 hecate.com/
drwxr-xr-x   3 rlopes  staff   102B 22 Dec 23:33 olx.com/

Request example:

curl -X POST -H "X-Fake-Domain: hecate.com" "http://localhost:9090/api/account/profile"

Response must be:

{
  "user": {
    "company": "OLX",
    "country": "PT",
    "email": "[email protected]",
    "id": 1,
    "name": "Rodrigo Lopes",
    "phone": "000000000",
    "phone_region": "PT",
    "username": "rlopes"
  }
}

Delay of response

If you want to simulate delay of response you can use the header X-Fake-Delay to do that, use the Millisecond

Request example:

time curl -X POST -H "X-Fake-Delay: 3000" -H "X-Fake-Domain: hecate.com" "http://localhost:9090/api/account/profile"

Response example:

curl ... 0.01s user 0.01s system 0% cpu 3.020 total

Condition Status Code

If you want to set a condition for your DATA response, you can test response 200 or 400 depending on value of request, you can set a additional field named CONDITIONS for that, if body of request match with field DATA will render the method that indicated ACTION.

{
    "CONDITIONS": [
        {
            "ACTION": "POST_200",
            "DATA": {
                "username": "[email protected]",
                "password": "correct_password"
            }
        },
        {
            "ACTION": "POST_400",
            "DATA": {
                "username": "[email protected]",
                "password": "wrong_password"
            }
        }
    ],
    "INPUT": {
        "username": "[email protected]",
        "password": "secret_password"
    },
    "POST_200": {
        "message": "Account authentication with success",
        "access_token": "2bc9ef94406489a5181fbd5898aa2202836810f2",
        "success": "true"
    },
    "POST_400": {
        "message": "Failed to authenticate user",
        "success": "false",
        "error": {
            "exception": "Exception: invalid_grant",
            "title": "Invalid username and password combination"
        }
    }
}

List of links available

You can see which links are available at FakeApi seed files, access the link http://localhost:9090/api this link will show list of endpoints available.

Json documentation

The docs will be generate automatic

{
    "domain": "default",
    "message": "List of endpoints available for this domain",
    "resource": {
        "Domain": "default",
        "Path": "fakes/default",
        "Docs": [
            {
                "Path": "fakes/default/api_account_confirmation_d019ccfd071164ae7ac8ca8a934a90e8b612.json",
                "Url": "/api/account/confirmation/d019ccfd071164ae7ac8ca8a934a90e8b612",
                "Error": "Something is worng with file api_account_confirmation_d019ccfd071164ae7ac8ca8a934a90e8b612.json error invalid character ':' after object key:value pair",
                "Endpoints": null
            },
            {
                "Path": "fakes/default/[email protected]",
                "Url": "/api/account/forgot/[email protected]",
                "Error": null,
                "Endpoints": [
                    {
                        "Method": "GET",
                        "StatusCode": 200,
                        "StatusText": "OK",
                        "Data": {
                            "data": {
                                "message": "User password recovery email was sent with success",
                                "success": true
                            }
                        }
                    },
                    ...
                ]
            },
            ...
        ]
    }
}

Web documentation

You can use web page friendly if you access http://localhost:9090/docs. this page will be generate in realtime the documents that you have in JSONS file.

This is a simple example of page:

Docs Home Page

When click at title the collapse will open then you can see the response.

Docs Collapse open

If the json has error the docs will render like this

Docs with error

Seed file for documentation

If you want to show more descriptions about your endpoint it is possible if you create a node DOC at you Seed files this node needs to have set title and description, you can see the example above.

  • DOC:

    • level: It is the category that this json belongs to.
    • title: Title with little text about endpoint.
    • description: Text more descriptive about what your endpoint does.
  • INPUT :

    • The text saying what your endpoints are expecting to receive from client/frontend, it validate if format of request is equal what was written in seed.

P.S: Seed file with comments:

{
    "DOC": {
        "title": "Validate account",
        "description": "This endpoint will validate the account changing flag 'pending' to 'activate'."
    },
    "INPUT": {
        "email": "[email protected]",
        "token": "d019ccfd071164ae7ac8ca8a934a90e8b612"
    },
    "POST_201": {
        "data": {
            "success": true,
            "message": "OK"
        }
    }
}

The web page will be rendered this seed above like it:

Docs with texts

Configuring FakeApi with Supervisor.

You need to enter in folder /etc/supervisor/conf.d and create a file with name fake-api.conf and inside you have so set the environment.

  • My app is in /var/www/fakeApi
  • My logs are in /var/log/fakeApi
[program:FakeApi]
environment=MACARON_ENV=production,FAKE_API=/var/www/fakeapiFAKE_API_CUSTOM=/var/www/fakeapi
directory=/var/www/fakeapi
command=/var/www/fakeapi/server web
autostart=true
autorestart=true
stderr_logfile=/var/log/fakeApi/err.log
stdout_logfile=/var/log/fakeApi/out.log

Configuring FakeApi with Nginx.

I am writing this step ....

server {
    listen   80; ## listen for ipv4; this line is default and implied
    #listen   [::]:80 default_server ipv6only=on; ## listen for ipv6

    root /usr/share/nginx/www;
    index index.html index.htm;

    # Make site accessible from http://localhost/
    server_name localhost fake-api.local fake-api.olx.com;

    location / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header X-Fake-Domain $host;
        proxy_set_header Host $host;
        proxy_pass http://127.0.0.1:9090;
    }

    # Next config of nginx...
}

P.S: By default the cross domain is always enabled.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].