All Projects → yahoo → parsec

yahoo / parsec

Licence: Apache-2.0 license
A collection of libraries and utilities to simplify the process of building web service applications.

Programming Languages

java
68154 projects - #9 most used programming language
groovy
2714 projects
shell
77523 projects

Projects that are alternatives of or similar to parsec

seamless
Seamless is a framework to set up reproducible computations (and visualizations) that respond to changes in cells. Cells contain the input data as well as the source code of the computations, and all cells can be edited interactively.
Stars: ✭ 19 (-44.12%)
Mutual labels:  web-services
ice-scripts
建议升级到 icejs。基于 webpack 的高可配置开发构建工具。
Stars: ✭ 45 (+32.35%)
Mutual labels:  build-tools
htoml
TOML file format parser in Haskell
Stars: ✭ 39 (+14.71%)
Mutual labels:  parsec
OpenISS
OpenISS -- a unified multimodal motion data delivery framework.
Stars: ✭ 22 (-35.29%)
Mutual labels:  web-services
RDLCPrinter
Wpf ReportViewer control and RDLCPrinter work with SQL Server LocalReport. You can export your report to PDF, Word or PNG Image...
Stars: ✭ 26 (-23.53%)
Mutual labels:  rdl
universal-scripts
Build universal apps without configuration.
Stars: ✭ 23 (-32.35%)
Mutual labels:  build-tools
GAlogger
Log R Events and R Usage to Google Analytics
Stars: ✭ 23 (-32.35%)
Mutual labels:  web-services
script.parsec
Launch Parsec from OSMC on your Raspberry Pi
Stars: ✭ 17 (-50%)
Mutual labels:  parsec
Jarvis
APL-based web service framework supporting JSON or REST
Stars: ✭ 17 (-50%)
Mutual labels:  web-services
b2
B2 makes it easy to build C++ projects, everywhere.
Stars: ✭ 38 (+11.76%)
Mutual labels:  build-tools
http4s-poc-api
POC: http4s http api on zio
Stars: ✭ 34 (+0%)
Mutual labels:  web-services
rsdmx
Tools for reading SDMX data and metadata in R
Stars: ✭ 93 (+173.53%)
Mutual labels:  web-services
lara
Lara Web Engine is a lightweight C# framework for web user interface development.
Stars: ✭ 121 (+255.88%)
Mutual labels:  web-services
rules proto grpc
Bazel rules for building Protobuf and gRPC code and libraries from proto_library targets
Stars: ✭ 201 (+491.18%)
Mutual labels:  build-tools
react-starter-kit
🚀 React starter kit for a modern single page (SPA) application (dependencies updated at 28 July 2017). Zero configuration. Ready to go. Just paste your code!
Stars: ✭ 26 (-23.53%)
Mutual labels:  build-tools
Responder
A familiar HTTP Service Framework for Python.
Stars: ✭ 3,569 (+10397.06%)
Mutual labels:  web-services
ParsecSoda
Parsec Soda is a custom open-source game streaming app that integrates with Parsec API and is focused in Host experience.
Stars: ✭ 135 (+297.06%)
Mutual labels:  parsec
passenger-datadog-monitor
Golang application for reporting Phusion Passenger stats to DataDog via statsD
Stars: ✭ 15 (-55.88%)
Mutual labels:  web-services
MarkRight
Markdown Parser Writen In Swift
Stars: ✭ 27 (-20.59%)
Mutual labels:  parsec
create-contentful-app
Bootstrap a Contentful App
Stars: ✭ 68 (+100%)
Mutual labels:  build-tools

Parsec Build Status

Parsec is a collection of libraries and utilities built upon Gradle and Jersey2, with the reliance on RDL. It is designed to reduce the effort of building web service applications, allowing you to spend more quality time elsewhere. By using Parsec, the grunt work is handled so you can concentrate on the logic and implementation side of development. More importantly, Parsec also provides flexibility and abstraction such that you can easily enforce your own standard, and apply to the pipeline.

Parsec offers a standardized end-to-end solution to quickly bring web service applications from concept to production. The goal of Parsec is to:

  • Provide a standard method for building APIs
  • Eliminate time spent in project and environment set up
  • Minimize time and effort spent on common repetitive tasks
  • Provide helper libraries and utilities for common tasks
  • Reduce the learning curve and maintenance cost
  • Provide client for your web service

If you are building a new project with Java, Parsec is definitely a good starting point.

Getting Started

Requirements

  • Java 1.8: check your jdk version using $ java -version or download Java JDK 1.8
  • Gradle (recommended version: >2.4): check your gradle version using $ gradle --v or run

$ sudo brew install gradle to install the latest gradle

After having Java 1.8 and Gradle installed with the proper version, you must do a one time setup to allow you to create a Parsec project without a build.gradle script.

$ vim ~/.gradle/init.gradle , then enter the following code:

gradle.beforeProject { prj ->
   prj.apply from: 'https://raw.githubusercontent.com/yahoo/parsec/master/parsec-template-plugin/installation/apply.groovy'
}

Create a New Project

To create a new Parsec project, run:

$ gradle createParsecProject -PgroupId='your.group.name' -PartifactId='your_project_name'

groupId refers to the namespace of your package, while the artifactId is your project name. If you do not specify the groupId or artifactId, you will be prompted to do so.

Create Schema

You need one or more RDL schema files to define your API specifications; they should be placed under src/main/rdl/ and be named as *.rdl. RDL is a machine-readable description of a schema that describes data types, as well as resources using those types.

You can start with this sample RDL file, save it as src/main/rdl/sample.rdl:

namespace your.group.name;
name sample;
version 1;

type User struct {
    string name (x_not_null="groups=insert", x_size="min=3,max=5,groups=update|insert");
    string occupation (x_not_null="groups=update", x_size="min=4,groups=update|insert");
    int32 age;
    string id (x_null="groups=insert");
}

resource User GET "/users/{id}" {
    int32 id;

    expected OK;
    exceptions {
        ResourceError INTERNAL_SERVER_ERROR;
        ResourceError BAD_REQUEST;
        ResourceError UNAUTHORIZED;
        ResourceError FORBIDDEN;
    }
}

resource string POST "/users" {
    User user (x_must_validate="insert");

    expected OK;
    exceptions {
        ResourceError INTERNAL_SERVER_ERROR;
        ResourceError BAD_REQUEST;
        ResourceError UNAUTHORIZED;
        ResourceError FORBIDDEN;
    }
}

resource string PUT "/users/{id}" {
    int32 id ;

    User user (x_must_validate="update");

    expected OK;
    exceptions {
        ResourceError INTERNAL_SERVER_ERROR;
        ResourceError BAD_REQUEST;
        ResourceError UNAUTHORIZED;
        ResourceError FORBIDDEN;
    }

}

Generate Code

After you have added your rdl files in the folder, you can use the command below to generate files:

$ gradle parsec-generate

Here is an example of the generated folder structure, based on the sample.rdl above:

$ tree build/generated-sources/
build/generated-sources/
└── java
    └── your
        └──group
            └──name
                └──parsec_generated
                    ├── ParsecApplication.java
                    ├── ParsecErrorBody.java
                    ├── ParsecErrorDetail.java
                    ├── ParsecExceptionMapper.java
                    ├── ParsecResourceError.java
                    ├── ParsecValidationGroups.java
                    ├── ParsecWebListener.java
                    ├── ParsecWrapperServlet.java
                    ├── ResourceContext.java
                    ├── ResourceError.java
                    ├── ResourceException.java
                    ├── SampleHandler.java
                    ├── SampleResources.java
                    ├── SampleServer.java
                    └── User.java

4 directories, 15 files

$ tree src/main/java/
src/main/java/
└── your
    └── group
        └──name
            ├── DefaultApplication.java
            ├── DefaultExceptionMapper.java
            ├── DefaultResourceContext.java
            ├── DefaultWebListener.java
            ├── SampleClient.java
            ├── SampleClientImpl.java
            └── SampleHandlerImpl.java

2 directories, 7 files

Parsec generated Java server, model code, and Java client for the server. The generated code would include:

  • Java models / data objects, for example: User.java
  • Jersey resource endpoints, for example: SampleResource.java
  • Handler interfaces, for example: SampleHandler.java - Handler implementations follow a naming convention: HandlerImpl.java
  • Java client for your web service, for example: SampleClient.java, SampleClientImpl.java

Java files are generated under ${baseDir}/build/generated-sources/java and the generated Java code are in sub-package .parsec_generated

Implement Handlers

Now you can start to implement your API by editing *HandlerImpl.java files. Here is an example of SampleHandlerImpl.java:

package your.group.name;

import your.group.name.parsec_generated.User;
import your.group.name.parsec_generated.SampleHandler;
import your.group.name.parsec_generated.ResourceContext;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * SampleHandlerImpl is interface implementation that implement SampleHandler interface.
 */
public class SampleHandlerImpl implements SampleHandler {

    @Override
    public User getUsersById(ResourceContext context, Integer id) {
        User user = new User();
        user.setName("user");
        return user;
    }

    @Override
    public String postUsers(ResourceContext context, User user) {
        return "Post to user " + user.getName() + "!\n";
    }

    @Override
    public String putUsersById(ResourceContext context, Integer id, User user) {
        return "put to user " + user.getName() + " by id " + id + "!\n";
    }

    @Override
    public ResourceContext newResourceContext(HttpServletRequest request, HttpServletResponse response) {
        return new DefaultResourceContext(request, response);
    }
}

Start your Server

Now you can start your server with:

$ gradle jettyRun

Check out your Swagger dashboard

Now you can run test with:

$ curl http://localhost:8080/api/sample/v1/users/1

{"age":0,"name":"user"}

$ curl -H 'Content-Type: application/json' -d '{"name":"user","age":10}' http://localhost:8080/api/sample/v1/users

Welcome to Parsec, user!

Use generated java client

Parsec friendly generates a simple client for your web service, including the interface and the implementation. Client implementation is base on com.ning.http.client.AsyncHttpClient, you can directly use it or modify it by your needs.

Here is the example of SampleClient.java, which provides methods to the APIs defined in src/main/rdl/sample.rdl.

package your.group.name;

import java.util.concurrent.CompletableFuture;
import your.group.name.parsec_generated.ResourceException;
import your.group.name.parsec_generated.User;


public interface SampleClient {
    CompletableFuture<User> getUser(int id) throws ResourceException;
    CompletableFuture<String> postUser(User user) throws ResourceException;
    CompletableFuture<String> putUser(int id, User user) throws ResourceException;
}

License

Copyright 2016, Yahoo Inc. Copyrights licensed under the Apache 2.0 License. See the accompanying LICENSE file for terms.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].