Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POST, PATCH, and other methods not supported? #133

Open
btelles opened this issue Jun 30, 2016 · 8 comments
Open

POST, PATCH, and other methods not supported? #133

btelles opened this issue Jun 30, 2016 · 8 comments

Comments

@btelles
Copy link
Contributor

btelles commented Jun 30, 2016

Hi there,

I've got a standard API that parses correctly in Apiary.io, and their mock server returns a 200, but drakov seems to always return "404: Cannot PATCH /groups/..."

Do non-GET requests need any special treatment? I'm using the example JS code in Apiary.io, and haven't been able to get a valid response all day. Here's the API:

FORMAT: 1A

# Group Users & Groups
## Group object [/groups/{id}]

+ Parameters
    + id (string, required)
        Group ID.

### Get group [GET]

+ Response 200 (application/json)

    + Attributes
        + data (GROUP)

+ Response 400 (application/json)

    + Attributes (ERROR)

+ Response 404 (application/json)

### Modify group [PATCH]

+ Request (application/json)

            {
                "data": {
                    "id": "acme",
                    "type": "group",
                    "attributes": {
                        "contact_emails": [
                            "wcoyote@acme.com",
                            "rrunner@acme.com",
                            "bbunny@acme.com"
                        ]
                      }
                }
            }

+ Response 200 (application/json)

    + Attributes
        + data (GROUP)

+ Response 400 (application/json)

    + Attributes (ERROR)



# GROUP

+ id: acme (string, required)
+ type: group (string, required)
+ attributes
    + organization: Acme (string, required)
    + organization_legal_name: Acme Inc. (string, required)
    + country_iso: us (string, required)
    + contact_emails: wcoyote@acme.com, rrunner@acme.com (array[string], required)
+ relationships
    + apikey
        + id: 57a24c23d0f49e1f13970f28a7a351b92f33b48c009dfefdaf2ce11140b2d456 (string, required)
        + type: apikey (string, required)
    + subscription
        + id: acme (string, required)
        + type: subscription (string, required)
    + administrators (array)
        + (object)
            + id: wcoyote
            + type: user
        + (object)
            + id: rrunner
            + type: user


And the CURL command:

curl --include \
     --request PATCH \
     --header "Content-Type: application/json" \
     --data-binary "    {
        \"data\": {
            \"id\": \"acme\",
            \"type\": \"group\",
            \"attributes\": {
                \"contact_emails\": [
                    \"wcoyote@acme.com\",
                    \"rrunner@acme.com\",
                    \"bbunny@acme.com\"
                ]
              }
        }
    }   " \
'http://localhost:5000/api/v3/groups/id'

And this is the code I'm using to run drakov (from a gulpfile.js):

var gulp = require('gulp');
var express = require('express');
var drakov = require('drakov');

gulp.task('drakov', function() {
  var argv = {
    sourceFiles: './api/apiary.apib',
    serverPort: 5000,
    autoOptions: true,
    method: ['PATCH', 'POST', 'PUT', 'DELETE', 'OPTIONS']
  }
  var app = express();
  drakov.middleware.init(app, argv, (err, middleWareFunction) => {
    app.use('/api/v3', middleWareFunction);
    app.listen(argv.serverPort);
  });
});

@yakovkhalinsky
Copy link
Contributor

There are some limitations to the current implementation around Express to do with HTTP methods as well as other factors.

My aim work be to actually move to another framework, perhaps HAPI to allow better support for all the different HTTP methods

@tonydeng
Copy link

I also encountered this problem.

start drakov logs

[INFO] No configuration files found
[INFO] Loading configuration from CLI
   DRAKOV STARTED
[LOG] Setup Route: GET /notes Get Notes
[LOG] Setup Route: POST /notes Create New Note
[LOG] Setup Route: GET /notes/:id Get Note
[LOG] Setup Route: PUT /notes/:id Update a Note
[LOG] Setup Route: DELETE /notes/:id Delete a Note
[LOG] Setup Route: GET /users Get users
[LOG] Setup Route: GET /tags
[LOG] Setup Route: GET /tags/:id
   Drakov 1.0.1      Listening on port 4007

HTTP PUT & POST Request

 http PUT http://localhost:4007/notes/1
HTTP/1.1 404 Not Found
Access-Control-Allow-Credentials: true
Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept
Access-Control-Allow-Origin: *
Connection: keep-alive
Content-Length: 20
Content-Type: text/html; charset=utf-8
Date: Tue, 16 Aug 2016 03:50:04 GMT
X-Content-Type-Options: nosniff
X-Powered-By: Drakov API Server

Cannot PUT /notes/1
http POST http://localhost:4007/notes
HTTP/1.1 404 Not Found
Access-Control-Allow-Credentials: true
Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept
Access-Control-Allow-Origin: *
Connection: keep-alive
Content-Length: 19
Content-Type: text/html; charset=utf-8
Date: Tue, 16 Aug 2016 03:50:24 GMT
X-Content-Type-Options: nosniff
X-Powered-By: Drakov API Server

Cannot POST /notes

Drakov request log

[LOG] PUT /notes/1
[LOG] GET /notes/1
[DRAKOV] GET /notes/{id}{?body} Get Note
[LOG] POST /notes

@paddingme
Copy link

+1

2 similar comments
@BrunoQuaresma
Copy link

+1

@freshsun
Copy link

freshsun commented Feb 7, 2017

+1

@yakovkhalinsky yakovkhalinsky self-assigned this Feb 9, 2017
@yakovkhalinsky yakovkhalinsky modified the milestone: 1.1.0 release Feb 9, 2017
@yakovkhalinsky
Copy link
Contributor

An update for everyone watching this issue.

This is now under active investigation and I am hoping to have a fix/update in the next couple of weeks 👍

@BrunoQuaresma
Copy link

Any updates?

@senyor-developer
Copy link

@yakovkhalinsky any updates on your "active" investigation :) ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants