zanata / fake-zanata-server

A simple REST server that presents a REST API similar to Zanata Server
MIT License
1 stars 2 forks source link

Fake Zanata Server

A simple REST server that presents a REST API similar to Zanata Server.

Purpose

Fake Zanata Server is a tool to support developers who are making apps that communicate with a real Zanata server. It can also be used to try out proposed REST endpoints for Zanata during API design.

Dependencies

Requires Node.js.

Contributions

To contribute to this server, create a branch or fork with your changes and submit a pull request for review.

Do not commit directly to master - it is not a maintainable practice. I will revert, rewrite or annihilate commits that are not reviewed through a pull request.

Usage

Install dependencies:

[prompt]$ npm install
...

Start the server with the default settings:

[prompt]$ npm start
...
REST endpoint listening at http://localhost:7878/zanata/rest, with latency 50..500

You can change some settings with command-line flags:

[prompt]$ npm start --port=1234 --latency=1000..5000 --path=rest --alloworigin="http://localhost:9000"
...
REST endpoint listening at http://localhost:1234/rest, with latency 1000..5000

Get resources from any of the endpoints listed under 'Endpoints' below:

[prompt]$ curl http://localhost:7878/zanata/rest/projects
[{
    "id": "tiny-project",
    "defaultType": "File",
    "name": "Tiny Project",
    "description": "A minimal project with a single version containing a single document.",
    "sourceViewURL": null,
    "sourceCheckoutURL": null,
    "links": [{
        "href": "p/tiny-project",
        "rel": "self",
        "type": "application/vnd.zanata.project+json"
    }],
    "iterations": null,
    "status": "ACTIVE"
  }
]
[prompt]$ curl http://localhost:7878/zanata/rest/projects/p/tiny-project
{
  "id": "tiny-project",
  "defaultType": "File",
  "name": "Tiny Project",
  "description": "A minimal project with a single version containing a single document.",
  "sourceViewURL": "source-view-url",
  "sourceCheckoutURL": "source-checkout-url",
  "links": null,
  "iterations": [{
      "id": "1",
      "links": [{
          "href": "iterations/i/1",
          "rel": "self",
          "type": "application/vnd.zanata.project.iteration+json"
      }],
      "status": "ACTIVE",
      "projectType": "File"
  }],
  "status": "ACTIVE"
}
[prompt]$ curl http://localhost:7878/zanata/rest/projects/p/tiny-project/iterations/i/1/r
[{
    "name": "hello.txt",
    "contentType": "text/plain",
    "lang": "en-US",
    "extensions": null,
    "type": "FILE",
    "revision": 1
}]

Data

The data available from this mock endpoint will intentionally be minimal, so that it is easy to reason about.

Tiny Project

A minimal project with a single version containing a single document.

Plurals Project

A project that has plurals in its source document. Has a single version and document.

Endpoints

Here is a list of the available endpoint URLs. Some are experimental URLs for use in development, that are not yet present in the real Zanata server.

Real endpoints

These exist on the real Zanata server

*Note: docId is encoded by replacing / with ,.

Fake endpoints

These do not exist on the real Zanata server, but may be implemented there in the future.