Skip to content

[Enhancement]: Provide $top as a synonym for $first in REST #2474

@JerryNixon

Description

@JerryNixon

Proposal

Provide $top as a synonym for $first in REST with no other behavioral change.

Reasons for this minor change:

Alignment with data source syntax is only a coincidence. Intuitive use and OData alignment are the primary drivers.

Database Keyword Used Example Syntax
Cosmos DB TOP SELECT TOP 5 Id, Name FROM Users
SQL Server TOP SELECT TOP 5 Id, Name FROM Users
MySQL LIMIT SELECT Id, Name FROM Users LIMIT 5
PostgreSQL LIMIT SELECT Id, Name FROM Users LIMIT 5

Why is this proposal specific to REST?

In GraphQL, first is more common than top. first is typically used in pagination, particularly with Relay-style connections. It specifies the number of items to retrieve starting from the current cursor. top is not standard in GraphQL queries. If you encounter it, it’s likely specific to a custom schema.

query {
  users(first: 5) {
    edges {
      node {
        id
        name
      }
    }
  }
}

Current behavior

URL QUERY
https://server/api/User?
$select=Id,Name
SELECT Id, Name
FROM User
&$first=10 SELECT TOP 10 Id, Name
FROM User

Proposed behavior

URL QUERY
https://server/api/User?
$select=Id,Name
SELECT Id, Name
FROM User
&$first=10 SELECT TOP 10 Id, Name
FROM User
&$top=10 SELECT TOP 10 Id, Name
FROM User

// end

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions