webpro/dyson được TopGit xếp vào nhóm dự án mã nguồn mở, với 832 sao trên GitHub.
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
When developing client-side applications, often either static JSON files, or an actual server, backend, datastore, or API, is used. Sometimes static files are too static, and sometimes an actual server is not available, not accessible, or too tedious to set up.
This is where dyson comes in. Get a full fake server for your application up and running in minutes.
Installation notes
Demo
Overview
Dynamic responses, based on
Request path
GET/POST parameters
Query parameters
Cookies
HTTP Methods: GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS
Dynamic HTTP status codes
CORS
Proxy (e.g. fallback to actual services)
Delayed responses
Required parameter validation
Includes random data generators
Includes dummy image generator
Use any external or local image service (included)
The path string is the usual argument provided to Express, as in app.get(path, callback);.
The template object may contain properties of the following types:
A Function will be invoked with arguments (params, query, body, cookies, headers).
Primitives of type String, Boolean, Number, Array are returned as-is
An Object will be recursively iterated.
A Promise will be replaced with its resolved value.
Note: the template itself can also be a function returning the actual data. The template function itself is also invoked with arguments (params, query, body, cookies, headers).
cache: true means that multiple requests to the same path will result in the same response
delay: n will delay the response with n milliseconds (or between [n, m] milliseconds)
proxy: false means that requests to this file can be skipped and sent to the configured proxy
size: fn is the number of objects in the collection
collection: true will return a collection
callback: fn
the provided default function is doing the hard work (can be overridden)
used as middleware in Express
must set res.body and call next() to render response
render: fn
the default function to render the response (basically res.send(200, res.body);)
used as middleware in Express
Fake data generators
You can use anything to generate data. Here are some suggestions:
Faker.js
Chance.js
dyson-generators
Just install the generator(s) in your project to use them in your templates:
npm install dyson-generators --save-dev
Containers
Containers can help if you need to send along some meta data, or wrap the response data in a specific way. Just use the container object, and return the data where you want it. Functions in the container object are invoked with arguments (params, query, data):
Would result in a 404 when requesting /feature/999.
Images
In addition to configured endpoints, dyson registers a dummy image service at /image. E.g. requesting /image/300x200 serves an image with given dimensions.
This service is a proxy to Dynamic Dummy Image Generator by Russell Heimlich.
JSONP
Override the render method of the Express middleware in the endpoint definition. In the example below, depending on the existence of the callback parameter, either raw JSON response is returned or it is wrapped with the provided callback:
If you want to run dyson over SSL you have to provide a (authority-signed or self-signed) certificate into the options.https the same way it's required for NodeJS built-in https module. Example:
Note: if running SSL on port 443, it will require sudo privileges.
GraphQL
If you want dyson to support GraphQL endpoints, you can build your own logic with the render override, or use dyson-graphql. Example:
npm install dyson-graphql --save-dev
const dysonGraphQl = require('dyson-graphql');
const schema = `
type User {
id: Int!
name: String!
}
type Query {
currentUser: User!
}
type Mutation {
createUser(name: String!): User!
updateUser(id: Int!, name: String!): User!
}
`;
module.exports = {
path: '/graphql',
method: 'POST',
render: dysonGraphQl(schema)
.query('currentUser', { id: 987, name: 'Jane Smart' })
.mutation('createUser', ({ name }) => ({ id: 456, name }))
.mutation('updateUser', ({ id, name }) => {
if (id < 1000) {
return { id, name };
}
throw new Error("Can't update user");
})
.build()
};
Custom middleware
If you need some custom middleware before or after the endpoints are registered, dyson can be initialized programmatically.
Then you can use the Express server instance (appBefore or appAfter in the example below) to install middleware before or after the dyson services are registered. An example:
You can also install dyson globally to start it from anywhere:
npm install -g dyson
Project
You can put your configuration files anywhere. The HTTP method is based on:
The method property in the configuration itself.
The folder, or an ancestor folder, containing the configuration is an HTTP method. For example mocks/post/sub/endpoint.js will be an endpoint listening to POST requests.
Defaults to GET.
dyson [dir]
This starts the services configured in [dir] at localhost:3000.
You can also provide an alternative port number by just adding it as a second argument (e.g. dyson path/ 8181).
Demo
For a demo project, see webpro/dyson-demo.
This demo was also installed with Heroku to dyson-demo.herokuapp.com.
Project Configuration
Optionally, you can put a dyson.json file next to the configuration folders (inside [dir]). It enables to configure some behavior of dyson:
Setting multiRequest to false disables the combined requests feature.
Setting bodyParserJsonLimit or bodyParserUrlencodedLimit to 1mb increases the limit to 1mb from the bodyParser's default of 100kb.
By default, the proxy is set to false
Watch/auto-restart
If you want to automatically restart dyson when you change your configuration objects, you can add nodemon as a devDependency. Say your configuration files are in the ./api folder, you can put this in your package.json:
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/webpro/dyson là nguồn chính thức.
webpro/dyson có bao nhiêu sao?
webpro/dyson có 832 sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/webpro/dyson. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
webpro/dyson có phải mã nguồn mở không?
TopGit chưa ghi nhận license cho webpro/dyson. Phần lớn repo public trên GitHub là mã nguồn mở, nhưng điều khoản khác nhau từng repo — mở file LICENSE để xác nhận.
webpro/dyson có tag gì không?
Bản đồng bộ chưa ghi nhận topic GitHub nào cho webpro/dyson. GitHub topics hiển thị ở thanh bên phải trang repo — đó là nơi đáng kiểm tra nhất.
webpro/dyson có website riêng không?
TopGit chưa ghi nhận URL trang chủ cho webpro/dyson. Phần README ở tab phía trên thường có link demo, hoặc xem mô tả GitHub của repo.
webpro/dyson còn được duy trì không?
TopGit chưa ghi nhận lần push gần đây của webpro/dyson. Xem lịch sử commit trực tiếp trên GitHub để biết thông tin chính xác nhất.
Đọc đầy đủ README ở tab phía trên.
Vẫn đang phân vân về dyson?
Một cú bấm sẽ gửi câu hỏi kèm trang này cho AI — xem AI nói gì về dyson.