Git Product home page Git Product logo

json-path-api's Introduction

Json Path API

A Web API that wraps https://github.com/json-path/JsonPath library calls.

tl;dr

Client/Browser → Amazon Route53 → Amazon API Gateway → AWS Lambda → Jayway JsonPath Library

Build and Deploy Commands

To build and deploy into your own AWS account, follow this:

# Build the zip file that contains the artifacts necessary for the Lambda (you need Docker for this to run successfully)
./gradlew clean buildZip

# Set S3 bucket and object where the zip will be uploaded
export STACK_NAME=json-path-api
# Use a bucket from your AWS account
export S3_BUCKET=<YOUR-S3-BUCKET-NAME-HERE>
export S3_KEY=lambdas/json-path

# Upload the built zip to S3
aws s3 cp build/distributions/json-path-api-1.0-SNAPSHOT.zip s3://$S3_BUCKET/$S3_KEY/JsonPathEvaluator.zip

# Create stack (one-time step) - this creates the Lambda function and the API Gateway endpoint (note it down)
sam deploy --s3-bucket $S3_BUCKET --stack-name $STACK_NAME --capabilities CAPABILITY_IAM --template-file cloudformation/template.yaml --parameter-overrides ParameterKey=LambdaCodeS3URI ParameterValue=s3://$S3_BUCKET/$S3_KEY/JsonPathEvaluator.zip

# (Optional) Update function after re-uploading a newly built zip
aws lambda update-function-code --function-name JsonPathEvaluator --s3-bucket $S3_BUCKET --s3-key $S3_KEY/JsonPathEvaluator.zip

# (Optional) Delete stack when you are done and do not need to retain the resources.
aws cloudformation delete-stack --stack-name $STACK_NAME

Test the API Endpoint

Replace the endpoint with the newly generated api in the below command and test.

export API_URL=<YOUR_API_URL_HERE>
curl $API_URL -H "Content-Type: application/json" -d \
'{
  "jsonToEvaluate" : "[{\"foo\" : \"foo1\",\"bar\" : \"bar1\"}{\"foo\" : \"foo2\"}]",
  "pathExpression" : "$[*].bar",
  "jsonPathOptions" : ["SUPPRESS_EXCEPTIONS","ALWAYS_RETURN_LIST"]
}'

You should see a successful result as shown below.

["bar1"]

If you intend to use a front-end, you may find this useful: https://github.com/psumiya/til/blob/main/http/options/cors.adoc

Here is a web application that uses a customized API endpoint as described above: https://sumiya.page/jpath.html

Lambda Runtime

  • Current Runtime: Java 21

  • Architecture: ARM64

In the past, I wrote about how the JRE for this project evolved from Java 11 to a custom Java 19 runtime here: https://sumiya.page/aws-lambda-custom-runtime-with-java-and-gradle.html

json-path-api's People

Contributors

psumiya avatar

Stargazers

 avatar

Watchers

 avatar  avatar  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.