Git Product home page Git Product logo

sling-rest's Introduction

Sling REST Service Framework

Background

AEM does not ship with any means of supporting a standard Jersey style REST service. Jersey and other popular REST frameworks don't appear to support the combination of Sling and OSGi. The main issue is that Sling manages all requests and there is no simple way of adding Jersey to a Sling controlled environment with digging into the deep internals of both Sling and Jersey.

Overview

This bundle provides framework for building out JSON based REST services. Services will register an OSGi service that implement the SlingRestService and mark individual methods with the SlingRestFunction annotation.

Documentaton

Please see Javadoc for SlingRestService and SlingRestFunction

Example Function

#!java

@SlingRestFunction("GET:/api/v1/user/{id}")
public RestResponse userInfo(SlingHttpServletRequest request, SlingHttpServletResponse response) throws SlingRestServiceException {
   String id = (String) request.getAttribute("ws.id");
   try  {
      ...
      String result = gson.toJson(returnObject);
      return new RestResponse.Builder(result).create();
   } catch (ApplicationException e) {
      throw new SlingRestServiceException.Builder(SlingRestServiceException.CATEGORY_ERROR, "Public message for end user")
      .setException(e)
      .setInternalMessage("Internal message that will be in logs for " + id)
      .create();
   }
}

Example URL: http://localhost:4502/api/v1/user/123

sling-rest's People

Watchers

Ryan L. Foster avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.