Git Product home page Git Product logo

drakov's People

Contributors

aj-jaswanth avatar apexitdhandav avatar artlogic avatar boguan avatar coagulant avatar dependabot[bot] avatar fastman avatar galkinrost avatar gitter-badger avatar khaliddermoumi avatar kingson-de avatar kosmotaur avatar krizalys avatar marcelogo avatar martinnuc avatar mgauthier avatar mobz avatar mohitjee avatar mrsanz avatar ongspxm avatar openhoat avatar pavelvanecek avatar pedro-teixeira avatar radion-chernyakov avatar skawaguchi avatar subinvarghesein avatar tallpsmith avatar tavio avatar vvscode avatar yakovkhalinsky avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

drakov's Issues

Having issues with POST, PUT and DELETE

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',

Deal with (optional) headers

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:

  • Separate responses for different headers
  • Replying with the default (first) response when the header is not present.
  • Define which headers could be optional (by default) and allow an option to define which headers should be optional

Add CORS support

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.

Parametric MD file

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

Not responding when sent data

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"}

I am new to mock server setup. Cannot get Drakov to work...

My .md file is very basic.

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 /

Find a better way to get feedback and ideas from the community

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.

Query parameters

I'm trying to include query parameters but it's not working, I'm using the correct syntax?

/users/{id}/{?include}

respect directory structure

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

Make stop() noop if drakov is not started

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.

Update changelog

The changelog has become a little out of date I should update it 🎱

Automatically respond to OPTIONS requests

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.

SSL Support

Add support for adding an SSL certification and key for handling HTTPS connections.

Required params and GET methods

Example

If i create something like this:

.
.
.
## Car [/api/car/{id}{?color}] 
+ Parameters 
  + id: `12` (string,required) 
  + color: `red` (string,required) 
.
.
.
.

Expected behaviour

When i send a request like get /api/var/12
Then i should receive some error about validate parameters

Problem

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

Wrong query string handling

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.

Grunt task for starting drakov

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'
    ]);
  });

drakov-cluster

Create a cluster of drakov processes that server different a different file set API blueprints.

cannot run drakov

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.

Add "Access-Control-Allow-Methods" for available methods

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

screen shot 2015-02-11 at 15 00 36

Get json response according to uri parameter value

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

GET /api.php?p=Y

  • Response 200 (application/json)

    { 
        json body
    }
    

GET /api.php?p=X

  • Response 200 (application/json)

    {
         json body
    }
    

Github Pages site

The README is getting a bit too chunky.

I would like to setup a nice github pages site for easier to read documentation.

Parametric headers or looser value matching.

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?

Drakov returns error when GET request has content-type: application/json in header

Unit test fails when a GET request has header with content-type: application/json
e.g

Retrieve all the things [GET]

  • Request
    • 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

Loading API Blueprint resources from string

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?

Way to relax `isBodyEqual` comparison?

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.

Add a flag to specify binding address

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.

Angular http service not responding

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.

Dredd fails because of setting encoding

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.