Git Product home page Git Product logo

request-api's Introduction

Request API

The purpose of this project is to show how a simple request API can be developed using the most used java libraries in the market as:

  • Spring Framework ( without XML)
  • Jersey
  • Jackson
  • Maven
  • Mockito
  • Junit4
  • Commons lang
  • Slf4 over log4j

After receiving "Berlin" via command line, the API will be http://.../Berlin

The return of this API will be around below

[

 {

 _id: 377078,
 key: null,
 name: "Potsdam",
 fullName: "Potsdam, Germany",
 iata_airport_code: null,
 type: "location",
 country: "Germany",

 geo_position: {
 latitude: 52.39886,
 longitude: 13.06566
 },
 location_id: 377078,
 inEurope: true,
 countryCode: "DE",
 coreCountry: true,
 distance: null
 },

 {
 _id: 410978,
 key: null,
 name: "Potsdam",
 fullName: "Potsdam, USA",
 iata_airport_code: null,
 type: "location",
 country: "USA",

 geo_position: {
 latitude: 44.66978,
 longitude: -74.98131
 },

 location_id: 410978,
 inEurope: false,
 countryCode: "US",
 coreCountry: false,
 distance: null
 }
 ]

Then, after parsing the result, a csv file will be created with the columns _id, name, type, latitude,longitude

Usage

Note, this project was created with Spring Tool suite (STS) and it doesn't mean you can't use others IDEs as (InteliJ, Eclipse....)

Running the project

The package will be in target folder, you can execute using the command below

java -jar request-api-x.x.x-SNAPSHOT.jar "Berlin"

On the same folder, a csv file will be created with name

System.currentTimeMillis() + ".csv" 

as example it could be

1443193089202.csv

STS Dev Details

Main class com.engyes.request.api.Application defined as

@Configuration
@ComponentScan( basePackages = "com.engyes.request" )
@PropertySource( { "classpath:application.properties" } )
public class Application {

	private static AnnotationConfigApplicationContext ctx;

	public static void main( String[] args ) {

		ctx = new AnnotationConfigApplicationContext( Application.class );
		ctx.getBean( RequestApi.class ).run( args );

	}

	@Bean
	public static PropertySourcesPlaceholderConfigurer propertyConfigInDev() {
		return new PropertySourcesPlaceholderConfigurer();
	}

}

As you can see the project is clean, it doesn't use xml to configure beans.

You can also change the main properties direct on properties file which is inject in the project by spring.

Build

mvn package

then check target directory for update project archive request-api-x.x.x-SNAPSHOT.jar.

There is also a original jar wihout dependencies in the folder target with name original-request-api-x.x.x-SNAPSHOT.jar

Test

mvn test

It will run the full test on project, the API is mocked, so, it will not make a real connection, instead, it will provide a fake return.

The csv will be created and deleted after each test.

History

  • 1.0 Initial version

request-api's People

Contributors

brrandrade avatar

Stargazers

 avatar Victor Moreira avatar

Watchers

 avatar

Forkers

r0adrunner

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.