aconex / drakov Goto Github PK
View Code? Open in Web Editor NEWMock Server that implements the API Blueprint specification
License: MIT License
Mock Server that implements the API Blueprint specification
License: MIT License
Hi, I noticed that this module makes use of the Resource Group
object defined in the ast format.
I'd just like to point out that they are now deprecated and will soon disappear from the spec altogether.
They've been replaced by the category
element.
See https://github.com/apiaryio/api-blueprint-ast#resource-group-object for more information.
Is this something that's currently on the development roadmap?
It would be nice to have drakov reload if any of the glob pattern matches change.
Does the request methods POST/PUT/DELETE work?
I've even tried setting up the example docs and couldn't get them to work.
ie. sourceFiles: 'node_modules/drakov/test/example/md/**.md',
Hi,
What do you think about adding an option to proxy not defined path from defined upstream server?
Let's try and start a discussion about (optional) headers.
In my use-case, you have to specify your language through the Accept-Language
header and depending on the selected language, the response is different.
+ Request
+ Header
Accept-Language: en-US
+ Response 200 (application/json)
// English response
+ Request
+ Header
Accept-Language: nl-BE
+ Response 200 (application/json)
// Dutch response
One thing I noticed however is that drakov will return a 404
if the header doesn't match the one specified in the blueprint. However, in my API the Accept-Language
header is optional and will default to en-US
if undefined.
Let's discuss two things:
Suggestioned from @galkinrost
function _log(){
if (stealthMode) {
return;
}
console.log(Array.prototype.slice.call(arguments).join(' '));
}
exports.log = function() {
[].unshift.call(arguments,'[LOG]');
_log(arguments);
};
exports.warn=function(){
[].unshift.call(arguments,'[WARN]');
_log(arguments);
};
I think it's fairly important to be able to support CORS. It should probably be configurable as well. I don't mind making a pull request unless this is already in the works.
It struck me that it may be useful to allow overrides of all the command line arguments to be loaded from a configuration file, i.e. config.js
that exports a bunch of properties as documented in the arguments.js
module https://github.com/Aconex/drakov/blob/master/lib/arguments.js
This thought occurred to me when I was considering the issues around bootstrapping a Drakov server inside a docker container.
Hi, i'm successfully using Drakov to mock my backend. Thank you for such useful tool!
I've just a question for you.. There is a way to program drakov to accept any date in a given field?
I've similar request body:
{"moneytransfer" : {"amount":200, "sender": "Luca", "receiver": "Mario", "transferDate": "03/07/2015"}}
Actually every day I use drakov I have to modify the .md file to update the transferDate field.. is it possible to write the .md file yust one time and say someting like: "transferDate": "any"
Thank you
Luca
Also need to make sure I document how to update this module for contributors who add things to argv
.
Optimist is deprecated and is no longer being maintained.
We should implement yargs
in place of optimist
:
https://github.com/bcoe/yargs
I get the correct response from…
curl --request POST http://127.0.0.1:3000/login -H "noredirect: true"
…but not from…
curl --request POST --data 'username=username&password=password' http://127.0.0.1:3000/login -H "noredirect: true"
Response: Cannot POST /login
When I use the same API blueprint on app.apiary.io both request work.
## Login [/login]
A Question object has the following attributes:
### Login [POST]
+ username (string) - A user name.
+ password (string) - A password.
+ Request
+ Headers
noredirect: true
+ Body
username=username&password=password
+ Response 200 (application/json)
{"status":"ok"}
FORMAT: 1A
# Fleetfoot API
This is the API Blueprint file for fleet foot API services.
# Group Login
## Login page [/]
### Get Login page [GET]
+ Response 200
I see Cannot GET / when I try... .What could be the problem? I am starting from command line. The output in the window is
DRAKOV STARTED
[LOG] Setup Route: GET / Get Login page
Drakov 0.1.7 Listening on port 3000
[LOG] GET /
I feel like we still have a lot we can do, but I'm not sure just posting issues is good enough.
Would love to hear from people either using or wanting to use Drakov about possible way to communicate with a community of users and potential users.
I'm trying to include query parameters but it's not working, I'm using the correct syntax?
/users/{id}/{?include}
Is there a way that Drakov can work nicely with Gulp?
Hi there!
It's noths.com here.
Our APIs need versioning, so the URLs will be prepended by the likes of "v1", "v2". The mock APIs will be exposed under all supported versions. We don't want to have a flat file structure with the same resource in multiple versions, like:
.
|____address-v1.md
|____address-v2.md
|____address-v3.md
|____checkout-v1.md
|____checkout-v2.md
|____checkout-v3.md
as this would get out of hand with hundreds of files pretty quickly. Also, multiple services we're running could have a resource with the exact same name, like /address
, so managing the names would become even more tricky.
We would like to organise them to indicate service/version/resource, like this:
.
|____checkout
| |____v1
| | |____address.md
| | |____checkout.md
| |____v2
| | |____address.md
| | |____checkout.md
| |____v3
| | |____address.md
| | |____checkout.md
|____suppliers
| |____v1
| | |____address.md
| |____v2
| | |____address.md
| |____v3
| | |____address.md
We would like to add an option called eg. prepend-paths
, so that the file system path gets prepended to the actual endpoints' URLs, so we'd get something like these given the directory structure just above:
GET /checkout/v1/address
GET /checkout/v1/checkout
GET /checkout/v2/address
GET /checkout/v2/checkout
GET /checkout/v3/address
GET /checkout/v3/checkout
and
GET /suppliers/v1/address
GET /suppliers/v2/address
GET /suppliers/v3/address
We're happy to do all the coding, just let us know if you'd welcome such an option.
Kind regards,
@SiCurious and @kosmotaur
Currently there is no way to check if drakov is running via API, so stop() should be a noop OR there should be an isRunning() function to check if the instance of drakov is running.
Waiting on the 4.12 version of express till we can provide full support for newer version of Node.js and start testing on io.js.
Run query parameter matching in 2 modes:
The changelog has become a little out of date I should update it 🎱
Per the latest spec: https://github.com/apiaryio/api-blueprint/blob/master/examples/10.%20Data%20Structures.md), Attributes provide a means of reusing common structures across multiple API endpoint descriptions. Would be great to get support for these into an upcoming release!
Wouldn't it make sense to automatically respond to OPTIONS
requests? Drakov knows about the HTTP methods that a certain URL can respond to so it can provide Allow
and Access-Control-Allow-Methods
headers in the response.
If this is possible/desirable I'd be happy to work on a patch for implementing it.
Add support for adding an SSL certification and key for handling HTTPS connections.
Currently the protagonist libary, which is responsible for parsing API Blueprint files into an AST, doesn't build on 0.11 or 0.12 of node.js
If i create something like this:
.
.
.
## Car [/api/car/{id}{?color}]
+ Parameters
+ id: `12` (string,required)
+ color: `red` (string,required)
.
.
.
.
When i send a request like get /api/var/12
Then i should receive some error about validate parameters
If i send the request above i'm receiving a valid request(200 status response). is that ok? (i'm new with drakov. so, i want to be sure that i'm not doing anything wrong (probably i did )
thanks for you help
Drakov seems to still have problems with query string parameters. As you can see in this build Drakov should register these 3 Urls from the Blueprint API file.
GET /index.php?action=stats&cat=account # Retrieve the account stats
GET /index.php?action=stats&cat=forum # Retrieve the forum stats
GET /index.php?action=stats&cat=groups # Retrieve the groups stats
The first request runs well, but at the second and third request Drakov returns the wrong responses.
1st request: All right
[LOG] GET /index.php?action=stats&cat=account
[DRAKOV] GET /index.php?action=stats&cat=account Retrieve the account stats
2nd and 3rd request: Returns the first response?
[LOG] GET /index.php?action=stats&cat=forum
[DRAKOV] GET /index.php?action=stats&cat=account Retrieve the account stats
[LOG] GET /index.php?action=stats&cat=groups
[DRAKOV] GET /index.php?action=stats&cat=account Retrieve the account stats
Is this a bug or am I doing something wrong? Oh, and please don't judge me for these crappy urls. 😔 They came from a legacy project and will hopefully change in near future.
Hi,
I have registered a basic task for starting drakov. I include this task when I call grunt serve.
Does the below config look ok to you?
grunt.registerTask('mock-api', 'Start drakov server', function() {
var drakovOptions = {
sourceFiles: './test/example/**/*.md',
serverPort: 3000
};
drakov.run(drakovOptions, function(err){
if (err) {
throw err;
console.log('-- STARTED --');
}
});
});
grunt.registerTask('serve', 'Compile then start a connect web server', function (target) {
if (target === 'dist') {
return grunt.task.run(['build', 'connect:dist:keepalive']);
}
grunt.task.run([
'mock-api',
'clean:server',
'wiredep',
'concurrent:server',
'autoprefixer:server',
'connect:livereload',
'watch'
]);
});
Create a cluster of drakov
processes that server different a different file set API blueprints.
Hi,
I am really struggling to get this to work!
I resolved all the issues I had trying to install this module on Windows 8.1.
Then I tried to run the module with an blueprint file I used from this project.
Cmd is:
drakov -f "./simple-api.md"
I was expecting to access it at localhost:3000/api/things
I get this error now:
{ code: 2,
message: 'the use of carriage return(s) \'\\r\' in source data isn\'t currently supported, please contact makers',
location: [ { index: 10, length: 1 } ] }
i assume this is issues with line endings?
Is it possible to run this at all in windows!!?
node version is 0.12.5
npm is 2.11.2
Any help is appreciated as Im banging my head here... ;-)
Thanks,
Shane.
I try to DELETE
angular resource, and get following error in Chrome Console.
XMLHttpRequest cannot load http://localhost:8080/concepts/12. Method DELETE is not allowed by Access-Control-Allow-Methods.
If i add Allow-Methodes header in request.js
everything works fine.
exports.headers = function(req, res, next) {
res.set('X-Powered-By', 'Drakov API Server');
res.set('Access-Control-Allow-Methods','DELETE'); // fix Allow-Methods error
next();
};
It would be nice, if you can dynamically add Header for all available methods
index.js exports the middleware, but package.json doesn't use that for its main
field. Also, the express middleware example has you using the drakov module itself, though that doesn't have an init
method.
Hi everyone,
How can I achieve to get json response according to uri parameter value? If p is equal to Y, I want to get first json body. But there is no p field in json body. If p is equal to X, I want to get second json body. I am using drakov as mock server. When I start drakov mock server, Both localhost:3000/api.php?p=Y and localhost:3000/api.php?p=X returns first json body.
drakov url : https://www.npmjs.com/package/drakov
Response 200 (application/json)
{
json body
}
Response 200 (application/json)
{
json body
}
The README is getting a bit too chunky.
I would like to setup a nice github pages site for easier to read documentation.
Is it possible to have the same loose matching on route segments with parameters for matching against headers?
I have a use case where one of the required request headers is an Authorization: Bearer <token>
header, but the<token>
can change for many different reasons.
Is it possible to loose matching on the headers?
Unit test fails when a GET request has header with content-type: application/json
e.g
Header
content-type: application/json
unit test fails and return following error
Error: expected [ { text: 'Zip2', id: '1' },
{ text: 'X.com', id: '2' },
{ text: 'SpaceX', id: '3' },
{ text: 'Solar City', id: '4' },
{ text: 'Hyperloop', id: '5' } ] response body, got {}
at error (C:\Users\Ahmadreza\Documents\GitHub\drakov\node_modules\supertest\lib\test.js:235:13)
at Test.assert (C:\Users\Ahmadreza\Documents\GitHub\drakov\node_modules\supertest\lib\test.js:166:19)
at assert (C:\Users\Ahmadreza\Documents\GitHub\drakov\node_modules\supertest\lib\test.js:132:12)
at C:\Users\Ahmadreza\Documents\GitHub\drakov\node_modules\supertest\lib\test.js:129:5
at Test.Request.callback (C:\Users\Ahmadreza\Documents\GitHub\drakov\node_modules\supertest\node_modules\superagent\lib\node\index.js:746:30)
at Test. (C:\Users\Ahmadreza\Documents\GitHub\drakov\node_modules\supertest\node_modules\superagent\lib\node\index.js:135:10)
at Test.emit (events.js:95:17)
at IncomingMessage. (C:\Users\Ahmadreza\Documents\GitHub\drakov\node_modules\supertest\node_modules\superagent\lib\node\index.js:938:12)
at IncomingMessage.emit (events.js:117:20)
at _stream_readable.js:943:16
Hi,
I've got another idea. It would be great if there was an option to load APIB resources from strings not only from paths.
The use case is using generated resources in test environment setup and omit the step when you have to resource content to file.
What do you think?
Currently, when making a POST request to drakov, the (json or form-encoded) request body must exactly match the example request body in the spec. This prevents basic testing of application request logic against the mock, because your app won't always be sending the same body content. Should the checking be relaxed (i.e. just checking to see if keys are present), or even removed completely?
I'm happy to submit a PR if either of these (or something else I haven't thought of here) sounds good.
Somewhere between version 0.1.3 and 0.1.5 drakov stopped listening on 0.0.0.0, which is useful in docker for example, if the default behaviour now is 127.0.0.1 it think that is good to have a flag to specify the listening address as it is impossible to run drakov on docker now.
Hi,
I have drakov running using grunt on localhost:3000.
[LOG] Setup Route: GET /subscribe Subscribe by email
Drakov 0.1.8 Listening on port 3000
-- STARTED --
My endpoint I can hit via browser or postman.
Example:
http://localhost:3000/subscribe?id=12345&type=xyz&email=xyz&hv=xyz
But when I try and call the api in angular, in the server console it logs continuously:
[LOG] OPTIONS /subscribe?id=12345&type=xyz&email=xyz&hv=xyz
Code snippet angular:
$http.get('http://localhost:3000/subscribe?id=12345&type=xyz&email=xyz&hv=xyz', {headers: {
'Custom-Header': 'a'}})
.success(function (response) {
console.log('Response ' + response);
});
My grunt config:
grunt.registerTask('mock-api', 'Start drakov server', function() {
var done = this.async();
var drakovOptions = {
sourceFiles: './doc/*.md',
serverPort: 3000
// autoOptions: true
//disableCORS: false
};
drakov.run(drakovOptions, function(err){
console.log('-- STARTED --');
if (err) {
throw err;
}
});
done();
});
NB: My angular app is running on a different port using connect on port 9000.
/api/things?page=1
should response differently to /api/things
Currently, when running Dredd on a Drakov instance it reports that the Content-Type
header is incorrect.
This is because Express adds ; charset=utf-8
to the Content-Type
header when setting the encoding on the request object (https://github.com/Aconex/drakov/blob/master/lib/middleware/request.js#L6).
Any particular reason why we're explicitly setting the encoding and not honoring the blueprint?
request:
body:
headers:
User-Agent: Dredd/0.4.7 (Darwin 14.3.0; x64)
uri: /notes
method: GET
expected:
headers:
Content-Type: application/json
body:
[
{
"id": 1,
"title": "Jogging in park"
},
{
"id": 2,
"title": "Pick-up posters from post-office"
}
]
statusCode: 200
actual:
statusCode: 200
headers:
x-powered-by: Drakov API Server
access-control-allow-origin: *
content-type: application/json; charset=utf-8
content-length: 104
etag: W/"68-91519068"
date: Sat, 14 Mar 2015 22:59:49 GMT
connection: keep-alive
body:
[{
"id": 1, "title": "Jogging in park"
}, {
"id": 2, "title": "Pick-up posters from post-office"
}]
Updating the blueprint to reflect the charset works fine, but it feels like we should support more than just utf-8 encoded payloads.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.