apiaryio / api-blueprint

API Blueprint
https://apiblueprint.org
MIT License
8.64k stars 2.14k forks source link

Specifying CRUD services #351

Closed mikail-khan closed 7 years ago

mikail-khan commented 7 years ago

I'm new to Blueprint and I am still learning the underlying model. I fleshed out a simple CRUD service and it seemed odd to me that I needed to group the HTTP verbs according to the URI pattern. For example,

## Foo [/foo]
### Whatever [POST]
...
## Foo [/foo/{id}]
### Whatever [GET]
### Whatever [PUT]
### Whatever [DELETE]

GET, PUT, and DELETE need an ID passed but for POST I don't.

Is this idomatic Blueprint or am I missing something? Is it not possible to avoid separating out the verbs like this.

rakis10 commented 7 years ago

Hi @cokleisli ,

I am new here also, trying to get familiar with API Blueprint.

I understand simple GET method but POST is more difficult

## Resource 1 [/resource/?id=1]

+ Parameters 
    + id (optional)- Path of resource

### Show resource [GET]

+ Response 200
...

### Post a Resource [POST]

+ Request (application/json) 

        {"question":"Do you want a Banana?"}

+ Response 201

    + Headers

            Location: /resource/1 

    + Body

            {"answer":"You posted your question :)")

Can any body check our code and help us with advice?

Thank

mikail-khan commented 7 years ago

@rakis10 your POST seems to be fine. What's the issue?

rakis10 commented 7 years ago

@cokleisli problem is that I cant GET resource/1. I am trying to POST some data and then access then with GET. Is that possible?

pksunkara commented 7 years ago

@cokleisli Yes, your blueprint looks idiomatic except for one thing. This is how I do it.

# Group User

## Users [/users]
### List all [GET]
### Create [POST]

## User [/user/{id}]
### Retrieve [GET]
### Update [PATCH]
### Delete [DELETE]
pksunkara commented 7 years ago

@rakis10 Looks like you are trying to say POST request should be sent to this url, /resource/?id=1