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

spec: allow named endpoints #198

Merged
merged 3 commits into from
Jun 8, 2015
Merged

spec: allow named endpoints #198

merged 3 commits into from
Jun 8, 2015

Conversation

LinusU
Copy link
Contributor

@LinusU LinusU commented May 26, 2015

See discussion in #196

@zdne
Copy link
Contributor

zdne commented May 27, 2015

When I think about it more conceptually – the endpoint as such is actually an action section in API Blueprint parlance (albeit it implies a new resource). Therefore it should be defined under Action and not resource as such.

This, however, has some implications – suddenly we can have "action" section at the top of a blueprint so the "Blueprint document structure" needs to be updated accordingly.

Internally, in the parser, this should be still picked up by Resource parser as it essentially creates a new resource (in AST) but this is opaque to user.

Furthermore parser should not warn when an action with the same URI template (but different method) is described, instead, it should add it under the respective resource.

Overall as simply as it looks it is actually quite complex problem :)

@LinusU
Copy link
Contributor Author

LinusU commented May 27, 2015

Hmm, I guess that in that case we'd want to change the behaviour of # GET /e1 as well, no?

I'm not sure if I'm happy with letting content "jump" to different places thought, it would make the internals quite a bit more complicated?

It would also make it complicated to do "guides" with blueprint since the content might not necessarily come in the order that you specify it in the markdown.

e.g.

# Create a user [POST /users]

...

# Log in as the user [POST /sessions]

...

# List all users [GET /users]

...

This would now list List all users before it listed Log in as the user making that call fail...


+ Request
+ Headers
Content-Type: application/json
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The content inside Headers and Body list items should be code blocks. So, indent them by 12 spaces.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@pksunkara
Copy link
Contributor

A few styling issues other than looks good. But I agree with @zdne that even though this issue looks simple, it is a bit complex one. We need to do some thinking on this.


Defined by a resource [name (identifier)](#def-identifier) followed by an [HTTP request method][httpmethods] and an [URI template][uritemplate] enclosed in square brackets `[]`:

# <identifier> [<HTTP request method> <URI template>]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way, if we are doing this, please add some info about this to the section title Header Keywords.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pksunkara I think it is OK to leave it as it is, because it is being already covered by "Combinations of an HTTP method and URI Template (e.g. GET /resource/{id})"

@zdne
Copy link
Contributor

zdne commented Jun 1, 2015

Hey @LinusU I was thinking about it a bit more and I think you are indeed right with:

I guess that in that case we'd want to change the behaviour of # GET /e1 as well, no?

Now doing that and also addressing

the content might not necessarily come in the order that you specify it in the markdown.

is quite radical change... So lets recap on what are the options:

1. Add name to an endpoint

Simply allow adding a name to # <HTTP request method> <URI template> action and leave everything else as is.

Pros

  • simplest way to add a name
  • doesn't change current behavior

Cons

  • everything stays under one resource - you will loose the order of these "named endpoints" in the case when they are hitting the same URI

2. Separate endpoints from resources

Introduce a new top-level "endpoint" section – for # <HTTP request method> <URI template> or # <Name> [<HTTP request method> <URI template>].

Pros

  • maintain order of endpoints
  • clearly distinguish between resource and endpoint architecture (or document structure)

Cons

  • need to change AST
  • changing behavior of existing things
  • much more complex on implementation side
  • affects all the tools

Thoughts ?

@LinusU
Copy link
Contributor Author

LinusU commented Jun 2, 2015

@zdne great writeup.

Number 1 is what I have implemented in this pull request, the only change really is to allow a name to the resource that gets generated.

I do like number 2 quite much thought, but as you say it's much more work involved. I think that we need to clarify a bit an endpoint is. Is it a path (e.g. /cars) or a method + path (e.g. GET /cars)? Would an endpoint contain an action? Or maybe any number of action? Or is the endpoint in itself an action?

If we try and work our way from the ast, which I think is a good approach, how would the new ast structure look?

I guess that it looks something like this currently:

  • category root
    • resource
      • action
    • category
      • resource
        • action

And it would become something like this if we added endpoints:

  • category root
    • endpoint
    • resource
      • action
    • category
      • endpoint
      • resource
        • action

Or maybe resource really just should be a category and action should be an endpoint. The uri would than be moved and placed in every endpoint instead of the one resource.

  • category root
    • endpoint
    • category
      • endpoint

Very simple ast at least. Every endpoint should then contain uriTemplate and method.

Maybe a good approach would be to implement number 1 now since that dosen't change anything for the existing ecosystem, and then try and figure out what we think about number 2.

I really like the ideas in number 2 thought, it makes it possible to specify APIs that aren't RESTful which I think is important.

@zdne
Copy link
Contributor

zdne commented Jun 4, 2015

@LinusU OK so let's break it into two parts

  1. Just adding names to top-level method + URI pairs
  2. Changing the internals to reflect ordering

@zdne
Copy link
Contributor

zdne commented Jun 4, 2015

I think that we need to clarify a bit an endpoint is.

👍

In the current context I am using the term "endpoint" for a method + URI pair

it makes it possible to specify APIs that aren't RESTful which I think is important.

👍


Note @smizell is currently working Refract Resource Namespace – this eventually should be the underlaying data structure – I believe he will address these main concept there (resources and transition) using some sort of recursive pattern.

TL;DR let's figure this one (point 2 as mentioned above) in the Resource namespace first and focus on just adding names to currently un-named method URI pairs.

Sounds good?

+ Headers
Content-Type: application/json
+ Body
{ "username": "Linus", "password": "test" }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consistence: Can we please use the same / similar example data as in the previous examples?

@zdne
Copy link
Contributor

zdne commented Jun 4, 2015

@LinusU Please address the review comments on the example and it is good to go! Thanks! 🎈

@LinusU
Copy link
Contributor Author

LinusU commented Jun 5, 2015

@zdne Should be good to go 👍


# <identifier> [<HTTP request method> <URI template>]

> **NOTE:** In the two latter cases the rest of this section represents the [Action section](#def-action-section) including its description and nested sections and **follows the rules of Action section instead**.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

- In the two latter
+ In the latter two

@LinusU
Copy link
Contributor Author

LinusU commented Jun 5, 2015

@pksunkara Done!

@pksunkara
Copy link
Contributor

Looks good. I am toggling this as "Passed Review". 👍

@pksunkara
Copy link
Contributor

@zdne Since I merged apiaryio/snowcrash#332, Do we merge this? Or should we wait for releasing it on Apiary?

@zdne
Copy link
Contributor

zdne commented Jun 5, 2015

@pksunkara I think we can merge this / update README (version supported in apiary) and release new version of API Blueprint...

@pksunkara
Copy link
Contributor

@LinusU Can you please make a new commit to this PR updating the current format to 1A9 from 1A8? Thanks.

@LinusU
Copy link
Contributor Author

LinusU commented Jun 8, 2015

I'm on it!

@LinusU
Copy link
Contributor Author

LinusU commented Jun 8, 2015

Done, I did not tag it since it seems that you have always tagged the merge commit :)

pksunkara added a commit that referenced this pull request Jun 8, 2015
spec: allow named endpoints
@pksunkara pksunkara merged commit d204824 into apiaryio:master Jun 8, 2015
@LinusU LinusU deleted the patch-1 branch June 8, 2015 07:53
@LinusU
Copy link
Contributor Author

LinusU commented Jun 8, 2015

Cheers 🍻

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

Successfully merging this pull request may close these issues.

3 participants