---
schema_version: "1"
id: 858c6eb046c8c80f5e40512933c81e773234c8a113ecde058f13c55f69297da2
title: RestResource Annotation
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/apexcode/apex_classes_annotation_rest_resource.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation_rest_resource.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: 3b3fb4f1e14710814e9b3a383cb79d5a05da70de941951af03a6000ac765cfc9
---
# RestResource Annotation

The @RestResource annotation is used at the class level and enables you to expose an Apex class as a REST resource.

Some considerations when using this annotation:

- The URL mapping is relative to https://instance.salesforce.com/services/apexrest/, where instance is a placeholder value.
- The URL mapping can contain a wildcard (\*).
- The URL mapping is case-sensitive. For example, a URL mapping for my\_url matches a REST resource containing my\_url and not My\_Url.
- To use this annotation, your Apex class must be defined as global.

## URL Guidelines

URL path mappings are as follows:

- The path must begin with a forward slash (/).
- The path can be up to 255 characters long.
- A wildcard (\*) that appears in a path must be preceded by a forward slash (/). Additionally, unless the wildcard is the last character in the path, it must be followed by a forward slash (/).

The rules for mapping URLs are:

- An exact match always wins.
- If no exact match is found, find all the patterns with wildcards that match, and then select the longest (by string length) of those.
- If no wildcard match is found, an HTTP response status code 404 is returned.

The URL for a namespaced class contains the namespace. For example, if your class is in namespace abc and the class is mapped to your\_url, then the API URL is modified as follows: https://instance.salesforce.com/services/apexrest/abc/your\_url/, where instance is a placeholder value. In the case of a URL collision, the namespaced class is always used.