{"id":1730,"date":"2026-09-30T09:00:00","date_gmt":"2026-09-30T03:30:00","guid":{"rendered":"https:\/\/swapnilzambare.com\/blog\/apex-rest-services-restresource\/"},"modified":"2026-11-15T11:31:49","modified_gmt":"2026-11-15T06:01:49","slug":"apex-rest-services-restresource","status":"publish","type":"post","link":"https:\/\/swapnilzambare.com\/blog\/apex-rest-services-restresource\/","title":{"rendered":"Apex REST Services: Build Your Own API with @RestResource"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Apex REST Services let you build your own API inside Salesforce, so outside systems can call your Apex logic over HTTPS. You mark a global class with @RestResource and its methods with annotations such as @HttpGet and @HttpPost. Salesforce then exposes them under \/services\/apexrest, with the same OAuth security as the standard REST API.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this post, you will build a course API with GET and POST, read the request, set status codes and write tests. It builds on <a href=\"https:\/\/swapnilzambare.com\/blog\/salesforce-rest-api-postman\/\">the Salesforce REST API with Postman<\/a>, <a href=\"https:\/\/swapnilzambare.com\/blog\/apex-classes-and-objects-constructors\/\">Apex classes and objects<\/a> and <a href=\"https:\/\/swapnilzambare.com\/blog\/apex-exception-handling-custom-exceptions\/\">Apex exception handling<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What are Apex REST Services?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Apex REST Services are global Apex classes annotated with @RestResource(urlMapping=&#8217;\/path\/*&#8217;). Each static method with an HTTP annotation handles one HTTP method for that URL. Salesforce reads the JSON request, calls your method and turns its return value back into JSON.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Think of the standard REST API as a supermarket with fixed shelves. You can buy any product, but only in its standard pack. An Apex REST service is a custom counter where you prepare a meal kit exactly as the customer asked, using several products at once.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why Apex REST Services Matter<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The standard API covers simple record work, but some callers need business logic. Here is why Apex REST Services matter at Bright Path Tutors.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>First, the website needs one call that creates a student, an enrolment and a payment record together.<\/li>\n\n<li>Also, the mobile app wants a small, custom response, not full records.<\/li>\n\n<li>Next, partner schools must only see open courses, filtered by rules in Apex.<\/li>\n\n<li>Validation can run in one place for every caller.<\/li>\n\n<li>Finally, fewer calls mean fewer API requests used.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">So custom services keep outside systems simple and your rules in one place.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How Apex REST Services Work<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Apex REST Services follow a clear request path. First, the caller gets an OAuth token for an integration user. Next, it sends a request to https:\/\/yourdomain.my.salesforce.com\/services\/apexrest\/ plus the urlMapping path. Then Salesforce finds the class and the method that matches the HTTP verb. After that, your method reads RestContext.request, runs the logic and returns a value. Finally, Salesforce serializes the result to JSON and sends it with the status code you set.<\/p>\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-rest-services-restresource-diagram-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-rest-services-restresource-diagram-1-1024x640.png\" alt=\"Apex REST Services diagram showing token, request, match, run and reply\" class=\"wp-image-1728\" srcset=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-rest-services-restresource-diagram-1-1024x640.png 1024w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-rest-services-restresource-diagram-1-300x188.png 300w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-rest-services-restresource-diagram-1-768x480.png 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">How a partner request reaches your Apex method.<\/figcaption><\/figure>\n\n\n<h3 class=\"wp-block-heading\">@RestResource and urlMapping<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The class must be global and use @RestResource. The urlMapping, such as \/courses\/*, is case-sensitive and can end with a wildcard.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">HTTP Method Annotations<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Use @HttpGet, @HttpPost, @HttpPut, @HttpPatch and @HttpDelete. Each must be on a global static method, and each verb appears once per class.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">RestContext<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">RestContext.request gives the URI, parameters, headers and body. RestContext.response lets you set the status code and headers.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Parameters and Return Values<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Method parameters are filled from the JSON body by name. Return values, such as a wrapper class, become the JSON response.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Security<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The service runs as the calling user. So use with sharing and user mode queries to respect access.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Apex REST Annotations at a Glance<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The table below lists the annotations and their usual jobs.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Annotation<\/th><th>HTTP method<\/th><th>Typical use<\/th><\/tr><\/thead><tbody><tr><td>@HttpGet<\/td><td>GET<\/td><td>Read records<\/td><\/tr><tr><td>@HttpPost<\/td><td>POST<\/td><td>Create records or run actions<\/td><\/tr><tr><td>@HttpPut<\/td><td>PUT<\/td><td>Create or replace<\/td><\/tr><tr><td>@HttpPatch<\/td><td>PATCH<\/td><td>Update some fields<\/td><\/tr><tr><td>@HttpDelete<\/td><td>DELETE<\/td><td>Remove a record<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Apex REST Services vs the Standard REST API<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The table below compares a custom service with the standard API.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Feature<\/th><th>Apex REST service<\/th><th>Standard REST API<\/th><\/tr><\/thead><tbody><tr><td>Code needed<\/td><td>Apex class and tests<\/td><td>None<\/td><\/tr><tr><td>Many objects in one call<\/td><td>Yes, your logic<\/td><td>Composite resources<\/td><\/tr><tr><td>Custom response shape<\/td><td>Yes<\/td><td>No, fixed format<\/td><\/tr><tr><td>Business rules<\/td><td>Run in Apex<\/td><td>Validation and triggers only<\/td><\/tr><tr><td>Maintenance<\/td><td>You own it<\/td><td>Salesforce owns it<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">When to use which is simple. Use the standard API for plain record work. Build Apex REST Services when callers need custom logic or a custom response.<\/p>\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-rest-services-restresource-diagram-2.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-rest-services-restresource-diagram-2-1024x640.png\" alt=\"Apex REST Services diagram comparing an Apex REST service with the standard REST API\" class=\"wp-image-1729\" srcset=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-rest-services-restresource-diagram-2-1024x640.png 1024w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-rest-services-restresource-diagram-2-300x188.png 300w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-rest-services-restresource-diagram-2-768x480.png 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">Apex REST service vs standard REST API.<\/figcaption><\/figure>\n\n\n<h2 class=\"wp-block-heading\">A Real Apex REST Services Example<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s build Apex REST Services at Bright Path Tutors. Partner schools can list open courses and request an enrolment.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: The Service Class<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>@RestResource(urlMapping='\/courses\/*')\nglobal with sharing class CourseApi {\n\n    global class CourseDto {\n        public Id id; public String name; public Decimal fee;\n        CourseDto(Course__c c) { id = c.Id; name = c.Name; fee = c.Fee__c; }\n    }\n\n    @HttpGet\n    global static List&lt;CourseDto&gt; getOpenCourses() {\n        String level = RestContext.request.params.get('level');\n        List&lt;CourseDto&gt; result = new List&lt;CourseDto&gt;();\n        for (Course__c c : [SELECT Id, Name, Fee__c FROM Course__c\n                            WHERE Status__c = 'Open' AND Level__c = :level\n                            WITH USER_MODE ORDER BY Name LIMIT 50]) {\n            result.add(new CourseDto(c));\n        }\n        return result;\n    }\n\n    @HttpPost\n    global static String requestEnrolment(Id courseId, String studentEmail) {\n        if (String.isBlank(studentEmail)) {\n            RestContext.response.statusCode = 400;\n            return 'studentEmail is required';\n        }\n        Enrolment_Request__c r = new Enrolment_Request__c(\n            Course__c = courseId, Student_Email__c = studentEmail);\n        insert as user r;\n        RestContext.response.statusCode = 201;\n        return r.Id;\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">GET reads the level from the URL and returns a small DTO list. POST takes courseId and studentEmail from the JSON body, checks input and returns 201 with the new Id.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: Call It<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>GET \/services\/apexrest\/courses\/?level=Beginner\n200 OK\n[ { \"id\": \"a01Kj00000Ab3xY\", \"name\": \"Apex Basics\", \"fee\": 5000 } ]\n\nPOST \/services\/apexrest\/courses\/\n{ \"courseId\": \"a01Kj00000Ab3xY\", \"studentEmail\": \"ravi@school.example\" }\n201 Created\n\"a05Kj00000Qw2Lm\"<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The JSON keys match the method parameter names, so Salesforce fills them in. Then the response shows the new request record Id.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 3: Test the Service<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>@IsTest\nprivate class CourseApiTest {\n    @IsTest\n    static void rejectsBlankEmail() {\n        RestContext.request = new RestRequest();\n        RestContext.response = new RestResponse();\n        String result = CourseApi.requestEnrolment(null, '');\n        Assert.areEqual(400, RestContext.response.statusCode);\n        Assert.areEqual('studentEmail is required', result);\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The test builds a fake request and response, then calls the method directly. So no HTTP call is needed to cover the code.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Apex REST Services and Versioning<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Callers depend on your URL and response shape. So add a version to the mapping, such as \/v1\/courses\/*, and create \/v2 for breaking changes. Old callers keep working while partners move over.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common Mistakes with Apex REST Services<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Forgetting global on the class or methods.<\/li>\n\n<li>Using without sharing and exposing records the caller should not see.<\/li>\n\n<li>Returning full sObjects with fields the partner should not get.<\/li>\n\n<li>Leaving every error as a 500 instead of setting clear status codes.<\/li>\n\n<li>Changing the response shape without a new version.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Best Practices for Apex REST Services<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Return small DTO classes, not full records.<\/li>\n\n<li>Use with sharing and WITH USER_MODE queries.<\/li>\n\n<li>Validate input and return 400 for bad requests.<\/li>\n\n<li>Version your urlMapping from day one.<\/li>\n\n<li>Keep logic in service classes, so the REST class stays thin.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Practice Task<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Add an @HttpPatch method that changes an enrolment request&#8217;s status. Hint: read the record Id from the end of RestContext.request.requestURI.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Most Asked Interview Questions on Apex REST Services<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Custom API questions are common for integration roles. Here are the 22 questions asked most about Apex REST Services.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Basic Questions on Apex REST Services<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q1: What is an Apex REST service?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A global Apex class exposed as a REST endpoint with @RestResource.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q2: What is the base URL of Apex REST services?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\/services\/apexrest\/ followed by the urlMapping path.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q3: Which access modifier must the class use?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Global, so code outside the org&#8217;s namespace can reach it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q4: Which annotations map HTTP methods?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">@HttpGet, @HttpPost, @HttpPut, @HttpPatch and @HttpDelete.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q5: Can a class have two @HttpGet methods?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">No, because each HTTP verb can appear only once per class.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q6: What is RestContext?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A class that gives access to the current RestRequest and RestResponse.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q7: How do callers authenticate?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">With an OAuth access token, the same as the standard REST API.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Code and Scenario Questions on Apex REST Services<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q8: How do you read a URL parameter?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Use RestContext.request.params.get(&#8216;name&#8217;).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q9: How do you read a record Id from the URL?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Take the part after the last slash in RestContext.request.requestURI.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q10: How do you set a 404 status?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Set RestContext.response.statusCode = 404 before returning.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q11: How do you receive a raw JSON body?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Use a method with no parameters and read RestContext.request.requestBody.toString().<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q12: How do you return a custom JSON shape?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Return a wrapper or DTO class, and Salesforce serializes it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q13: How do you test an Apex REST service?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Set RestContext.request and response in the test, then call the static method directly.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q14: How do you stop partners seeing private records?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Use with sharing, user mode queries and a least-privilege integration user.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Advanced Questions on Apex REST Services<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q15: How do you version an Apex REST API?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Put a version in urlMapping, such as \/v1\/courses\/*, and add new versions for breaking changes.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q16: When do you choose Apex REST over the composite API?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When you need business rules or a custom response that standard resources cannot give.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q17: How are governor limits applied?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Each request is one transaction, so normal synchronous limits apply.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q18: How do you handle errors consistently?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Catch exceptions, set a matching status code and return a standard error object.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q19: Can Apex REST services accept XML?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Yes, because Salesforce can deserialize XML into parameters, though JSON is more common.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q20: How do you make POST requests safe to retry?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Accept a unique request key and upsert on an external ID field.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q21: What is the difference between PUT and PATCH here?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">PUT usually replaces a whole resource, while PATCH changes some fields.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q22: How do Experience Cloud guest users affect Apex REST?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Guest access needs a site and strict guest security, so most APIs require authenticated users.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Official Resources<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/developer.salesforce.com\/docs\/platform\/apex-dev\/references\/apex-dev\/apex-rest.html\" target=\"_blank\" rel=\"noopener noreferrer\">Exposing Apex Classes as REST Web Services (Apex Developer Guide)<\/a><\/li>\n\n<li><a href=\"https:\/\/trailhead.salesforce.com\/content\/learn\/modules\/apex_integration_services\/apex_integration_webservices\" target=\"_blank\" rel=\"noopener noreferrer\">Apex Web Services (Trailhead)<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Quick Recap<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Apex REST Services expose your Apex under \/services\/apexrest.<\/li>\n\n<li>The class is global and uses @RestResource with a urlMapping.<\/li>\n\n<li>HTTP annotations map verbs to global static methods.<\/li>\n\n<li>RestContext gives the request and lets you set status codes.<\/li>\n\n<li>Use with sharing, DTOs and versioned URLs.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">What&#8217;s Next?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Some enterprise systems still speak SOAP and XML. Next, read our guide to <a href=\"https:\/\/swapnilzambare.com\/blog\/salesforce-soap-api-wsdl\/\">the Salesforce SOAP API and SOAP callouts<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Apex REST Services let you build your own API inside Salesforce, so outside systems can call your Apex logic over HTTPS. You mark a&hellip;<\/p>\n","protected":false},"author":1,"featured_media":1727,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_swapz_level":"","_swapz_series_part":0,"_swapz_hide_toc":false,"_swapz_hide_featured":false,"_swapz_description":"","footnotes":""},"categories":[246,8,96],"tags":[68,98,81],"swapz_series":[],"class_list":["post-1730","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-integration-apis","category-salesforce","category-salesforce-developer","tag-advanced","tag-apex","tag-integration"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Apex REST Services with @RestResource Explained<\/title>\n<meta name=\"description\" content=\"Apex REST Services explained simply: @RestResource, @HttpGet, @HttpPost, RestContext, status codes, security, testing and 22 interview Q&amp;A.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/swapnilzambare.com\/blog\/apex-rest-services-restresource\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Apex REST Services with @RestResource Explained\" \/>\n<meta property=\"og:description\" content=\"Apex REST Services explained simply: @RestResource, @HttpGet, @HttpPost, RestContext, status codes, security, testing and 22 interview Q&amp;A.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/swapnilzambare.com\/blog\/apex-rest-services-restresource\/\" \/>\n<meta property=\"og:site_name\" content=\"Swapnil Zambare - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-09-30T03:30:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-11-15T06:01:49+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-rest-services-restresource-featured.png\" \/>\n\t<meta property=\"og:image:width\" content=\"2400\" \/>\n\t<meta property=\"og:image:height\" content=\"1260\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Swapnil Zambare\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Swapnil Zambare\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-rest-services-restresource\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-rest-services-restresource\\\/\"},\"author\":{\"name\":\"Swapnil Zambare\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/person\\\/10b09224c8bcc562716e86789427592a\"},\"headline\":\"Apex REST Services: Build Your Own API with @RestResource\",\"datePublished\":\"2026-09-30T03:30:00+00:00\",\"dateModified\":\"2026-11-15T06:01:49+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-rest-services-restresource\\\/\"},\"wordCount\":1477,\"publisher\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-rest-services-restresource\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/apex-rest-services-restresource-featured.png\",\"keywords\":[\"Advanced\",\"Apex\",\"Integration\"],\"articleSection\":[\"Integration and APIs\",\"Salesforce\",\"Salesforce Developer\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-rest-services-restresource\\\/\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-rest-services-restresource\\\/\",\"name\":\"Apex REST Services with @RestResource Explained\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-rest-services-restresource\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-rest-services-restresource\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/apex-rest-services-restresource-featured.png\",\"datePublished\":\"2026-09-30T03:30:00+00:00\",\"dateModified\":\"2026-11-15T06:01:49+00:00\",\"description\":\"Apex REST Services explained simply: @RestResource, @HttpGet, @HttpPost, RestContext, status codes, security, testing and 22 interview Q&A.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-rest-services-restresource\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-rest-services-restresource\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-rest-services-restresource\\\/#primaryimage\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/apex-rest-services-restresource-featured.png\",\"contentUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/apex-rest-services-restresource-featured.png\",\"width\":2400,\"height\":1260,\"caption\":\"Apex REST Services featured image: title card with an integration code example\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-rest-services-restresource\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Apex REST Services: Build Your Own API with @RestResource\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/\",\"name\":\"Swapnil Zambare - Blog\",\"description\":\"Salesforce &amp; Tech Guides\",\"publisher\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#organization\",\"name\":\"Swapnil Zambare - Blog\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/09\\\/site-icon-512.png\",\"contentUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/09\\\/site-icon-512.png\",\"width\":512,\"height\":512,\"caption\":\"Swapnil Zambare - Blog\"},\"image\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.linkedin.com\\\/in\\\/theSwapnilZambare\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/person\\\/10b09224c8bcc562716e86789427592a\",\"name\":\"Swapnil Zambare\",\"sameAs\":[\"https:\\\/\\\/swapnilzambare.com\\\/blog\"],\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/author\\\/swapnil-zambare\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Apex REST Services with @RestResource Explained","description":"Apex REST Services explained simply: @RestResource, @HttpGet, @HttpPost, RestContext, status codes, security, testing and 22 interview Q&A.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/swapnilzambare.com\/blog\/apex-rest-services-restresource\/","og_locale":"en_US","og_type":"article","og_title":"Apex REST Services with @RestResource Explained","og_description":"Apex REST Services explained simply: @RestResource, @HttpGet, @HttpPost, RestContext, status codes, security, testing and 22 interview Q&A.","og_url":"https:\/\/swapnilzambare.com\/blog\/apex-rest-services-restresource\/","og_site_name":"Swapnil Zambare - Blog","article_published_time":"2026-09-30T03:30:00+00:00","article_modified_time":"2026-11-15T06:01:49+00:00","og_image":[{"width":2400,"height":1260,"url":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-rest-services-restresource-featured.png","type":"image\/png"}],"author":"Swapnil Zambare","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Swapnil Zambare","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/swapnilzambare.com\/blog\/apex-rest-services-restresource\/#article","isPartOf":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-rest-services-restresource\/"},"author":{"name":"Swapnil Zambare","@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/person\/10b09224c8bcc562716e86789427592a"},"headline":"Apex REST Services: Build Your Own API with @RestResource","datePublished":"2026-09-30T03:30:00+00:00","dateModified":"2026-11-15T06:01:49+00:00","mainEntityOfPage":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-rest-services-restresource\/"},"wordCount":1477,"publisher":{"@id":"https:\/\/swapnilzambare.com\/blog\/#organization"},"image":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-rest-services-restresource\/#primaryimage"},"thumbnailUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-rest-services-restresource-featured.png","keywords":["Advanced","Apex","Integration"],"articleSection":["Integration and APIs","Salesforce","Salesforce Developer"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/swapnilzambare.com\/blog\/apex-rest-services-restresource\/","url":"https:\/\/swapnilzambare.com\/blog\/apex-rest-services-restresource\/","name":"Apex REST Services with @RestResource Explained","isPartOf":{"@id":"https:\/\/swapnilzambare.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-rest-services-restresource\/#primaryimage"},"image":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-rest-services-restresource\/#primaryimage"},"thumbnailUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-rest-services-restresource-featured.png","datePublished":"2026-09-30T03:30:00+00:00","dateModified":"2026-11-15T06:01:49+00:00","description":"Apex REST Services explained simply: @RestResource, @HttpGet, @HttpPost, RestContext, status codes, security, testing and 22 interview Q&A.","breadcrumb":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-rest-services-restresource\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/swapnilzambare.com\/blog\/apex-rest-services-restresource\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/swapnilzambare.com\/blog\/apex-rest-services-restresource\/#primaryimage","url":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-rest-services-restresource-featured.png","contentUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-rest-services-restresource-featured.png","width":2400,"height":1260,"caption":"Apex REST Services featured image: title card with an integration code example"},{"@type":"BreadcrumbList","@id":"https:\/\/swapnilzambare.com\/blog\/apex-rest-services-restresource\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/swapnilzambare.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Apex REST Services: Build Your Own API with @RestResource"}]},{"@type":"WebSite","@id":"https:\/\/swapnilzambare.com\/blog\/#website","url":"https:\/\/swapnilzambare.com\/blog\/","name":"Swapnil Zambare - Blog","description":"Salesforce &amp; Tech Guides","publisher":{"@id":"https:\/\/swapnilzambare.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/swapnilzambare.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/swapnilzambare.com\/blog\/#organization","name":"Swapnil Zambare - Blog","url":"https:\/\/swapnilzambare.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/09\/site-icon-512.png","contentUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/09\/site-icon-512.png","width":512,"height":512,"caption":"Swapnil Zambare - Blog"},"image":{"@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.linkedin.com\/in\/theSwapnilZambare"]},{"@type":"Person","@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/person\/10b09224c8bcc562716e86789427592a","name":"Swapnil Zambare","sameAs":["https:\/\/swapnilzambare.com\/blog"],"url":"https:\/\/swapnilzambare.com\/blog\/author\/swapnil-zambare\/"}]}},"_links":{"self":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/posts\/1730","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/comments?post=1730"}],"version-history":[{"count":1,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/posts\/1730\/revisions"}],"predecessor-version":[{"id":2333,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/posts\/1730\/revisions\/2333"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/media\/1727"}],"wp:attachment":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/media?parent=1730"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/categories?post=1730"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/tags?post=1730"},{"taxonomy":"swapz_series","embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/swapz_series?post=1730"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}